Skip to content

Commit

Permalink
Implemented support for processing tags (proycon/folia#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Apr 2, 2021
1 parent c594440 commit 6789f17
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions folia/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,8 @@ def __getattr__(self, attr):
#overriding getattr so we can get defaults here rather than needing a copy on each element, saves memory
if attr in ('set','cls','processor', 'confidence','datetime','n','href','src','speaker','begintime','endtime','xlinktype','xlinktitle','xlinklabel','xlinkrole','xlinkshow','label', 'textclass', 'metadata','exclusive', 'preservespace'):
return None
elif attr == 'tag':
return []
elif attr == 'annotator':
if self.processor:
return self.processor.name
Expand Down Expand Up @@ -989,6 +991,11 @@ def parsecommonarguments(self, doc, **kwargs):
if Attrib.TEXTCLASS in supported:
self.textclass = "current"

if 'tag' in kwargs:
if kwargs['tag']:
self.tags = kwargs['tag'].split(" ")
del kwargs['tag']

if Attrib.SPACE in supported:
self.space = True #use spacing as determined by textdelimiter
if 'space' in kwargs:
Expand Down Expand Up @@ -2611,6 +2618,10 @@ def xml(self, attribs = None,elements = None, skipchildren = False, form = Form.
if self.metadata and self.metadata in self.doc.submetadata:
attribs['metadata'] = self.metadata

if 'tag' not in attribs: #do not override if caller already set it
if self.tags:
attribs['tag'] = " ".join(self.tags)

if self.XLINK:
if self.href:
attribs['{http://www.w3.org/1999/xlink}href'] = self.href
Expand Down Expand Up @@ -3162,6 +3173,8 @@ def relaxng(cls, includechildren=True,extraattribs = None, extraelements=None, o
attribs.append(RXE.attribute(name='space') )
elif Attrib.SPACE in cls.OPTIONAL_ATTRIBS:
attribs.append( RXE.optional( RXE.attribute(name='space') ) )
if Attrib.TAG in cls.OPTIONAL_ATTRIBS:
attribs.append( RXE.optional( RXE.attribute(name='tag') ) )
attribs.append( RXE.optional( RXE.attribute(name='typegroup') ) ) #used in explicit form only
attribs.append( RXE.optional(RXE.attribute(RXE.data(type='string',datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'),name='space', ns="http://www.w3.org/XML/1998/namespace")) ) #xml:space attribute

Expand Down Expand Up @@ -3382,6 +3395,27 @@ def incorrection(self):
e = e.parent
return None

def tag(self, tag):
"""Add a processing tag"""
if ' ' in tag:
raise ValueError("Processing tags may not contain spaces")
if self.tags:
self.tags.append(tag)
else:
self.tags = [tag]

def hastag(self, tag):
"""Check whether a processing tag is present"""
return tag in self.tags

def untag(self, tag):
"""Remove a processing tag"""
if tag in self.tags:
self.tags.remove(tag)
return True
else:
return False

class AbstractHigherOrderAnnotation(AbstractElement):
pass

Expand Down Expand Up @@ -3482,6 +3516,7 @@ def parsexml(Class, node, doc, **kwargs):
kwargs['value'] = node.text
return super(Comment,Class).parsexml(node, doc, **kwargs)


class AllowCorrections(object):
def correct(self, **kwargs):
"""Apply a correction (TODO: documentation to be written still)"""
Expand Down

0 comments on commit 6789f17

Please sign in to comment.