-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from acdh-oeaw/dev
new function added
- Loading branch information
Showing
6 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ | |
/dist | ||
/composer.lock | ||
/vendor | ||
env | ||
.tox | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
import json | ||
import pkg_resources | ||
import re | ||
|
||
def get_rules(): | ||
""" returns a list of regex pattern mateches | ||
def getRules(): | ||
#with open(pkg_resources.resource_string(__name__, 'rules.json'), 'r') as f: | ||
:return: a list of regex patterns to normalize Authority IDs | ||
:rtype: list | ||
""" | ||
return json.loads(pkg_resources.resource_string(__name__, 'rules.json')) | ||
#return rules | ||
|
||
|
||
def get_normalized_uri(uri): | ||
""" takes a normdata uri and returns a normlalized version | ||
:param uri: A normdata uri | ||
:param type: str | ||
:return: The normalized URI | ||
:rtype: str | ||
""" | ||
for x in get_rules(): | ||
uri = re.sub(x['match'], x['replace'], uri) | ||
return uri |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import unittest | ||
from AcdhUriNormRules.AcdhUriNormRules import get_rules, get_normalized_uri | ||
|
||
SAMPLES = [ | ||
[ | ||
"http://sws.geonames.org/1232324343/linz.html", | ||
"https://www.geonames.org/1232324343" | ||
], | ||
[ | ||
"http://d-nb.info/gnd/4074255-6/", | ||
"https://d-nb.info/gnd/4074255-6" | ||
], | ||
[ | ||
"https://d-nb.info/gnd/4074255-6", | ||
"https://d-nb.info/gnd/4074255-6" | ||
] | ||
] | ||
|
||
class TestNormalizer(unittest.TestCase): | ||
def test__001_load_list(self): | ||
rules = get_rules() | ||
self.assertEqual(type(rules), list, "should be type 'list' ") | ||
|
||
def test__002_test_patterns(self): | ||
for x in SAMPLES: | ||
new_uri = get_normalized_uri(x[0]) | ||
self.assertEqual(x[1], new_uri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[tox] | ||
envlist = py35, py36, py37, py38 | ||
|
||
[testenv] | ||
setenv = | ||
PYTHONPATH = {toxinidir} | ||
|
||
commands = python setup.py test |