Skip to content

Commit

Permalink
Fixes for aliases #33 (proycon/folia#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Sep 25, 2017
1 parent 6093c80 commit 2f48ac5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pynlpl/formats/folia.py
Original file line number Diff line number Diff line change
Expand Up @@ -6791,6 +6791,8 @@ def declare(self, annotationtype, set, **kwargs):

if inspect.isclass(annotationtype):
annotationtype = annotationtype.ANNOTATIONTYPE
if annotationtype in self.alias_set and set in self.alias_set[annotationtype]:
raise ValueError("Set " + set + " conflicts with alias, may not be equal!")
if not (annotationtype, set) in self.annotations:
self.annotations.append( (annotationtype,set) )
if set and self.loadsetdefinitions and not set in self.setdefinitions:
Expand All @@ -6800,14 +6802,12 @@ def declare(self, annotationtype, set, **kwargs):
self.annotationdefaults[annotationtype] = {}
self.annotationdefaults[annotationtype][set] = kwargs
if 'alias' in kwargs:
if annotationtype in self.set_alias and self.set_alias[annotationtype][set] != kwargs['alias']:
if annotationtype in self.set_alias and set in self.set_alias[annotationtype] and self.set_alias[annotationtype][set] != kwargs['alias']:
raise ValueError("Redeclaring set " + set + " with another alias ('"+kwargs['alias']+"') is not allowed!")
if annotationtype in self.alias_set and self.alias_set[annotationtype][kwargs['alias']] != set:
if annotationtype in self.alias_set and kwargs['alias'] in self.alias_set[annotationtype] and self.alias_set[annotationtype][kwargs['alias']] != set:
raise ValueError("Redeclaring alias " + kwargs['alias'] + " with another set ('"+set+"') is not allowed!")
if annotationtype in self.set_alias and kwargs['alias'] in self.set_alias[annotationtype]:
raise ValueError("Alias " + kwargs['alias'] + " conflicts with set name, may not be equal!")
if annotationtype in self.set_alias and set in self.alias_set[annotationtype]:
raise ValueError("Set " + set + " conflicts with alias, may not be equal!")
if annotationtype not in self.alias_set:
self.alias_set[annotationtype] = {}
if annotationtype not in self.set_alias:
Expand Down
2 changes: 1 addition & 1 deletion pynlpl/tests/folia.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ def test102n_aliases(self):
<metadata type="native">n"
<annotations>n"
<gap-annotation set="some very convoluted url or such which clutters all" alias="gap-set" datetime="2012-06-18T17:49"/>
<div-annotation set="a long div annotation name" alias="div-set" datetime="2012-06-18T17:49"/>
<division-annotation set="a long div annotation name" alias="div-set" datetime="2012-06-18T17:49"/>
</annotations>
</metadata>
<text xml:id="example.text.1">
Expand Down

0 comments on commit 2f48ac5

Please sign in to comment.