Skip to content

Commit

Permalink
add rights info to oa wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Bridget Almas committed Nov 21, 2017
1 parent ee7aac7 commit 243408c
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 22 deletions.
4 changes: 4 additions & 0 deletions morphsvc/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ ENGINES_HAZM_CNAME = "morphsvc.lib.engines.HazmEngine.HazmEngine"
PARSERS_MORPHEUS_PATH = "/home/balmas/workspace/morpheus/dist/bin/platform/Linux_x86-gcc4/morpheus"
PARSERS_MORPHEUS_STEMLIBDIR = "/home/balmas/workspace/morpheus/dist/stemlib"
PARSERS_MORPHEUS_URI = "org.perseus:tools:morpheus.v1"
PARSERS_MORPHEUS_RIGHTS = "Morphology provided by Morpheus from the Perseus Digital Library at Tufts University."
PARSERS_ARAMORPH_URI = "net.alpheios:tools:aramorph.v2"
PARSERS_ARAMORPH_RIGHTS = "Morphology provided by Buckwalter Arabic Morphological Analyzer Version 2.0 from QUAMUS LLC (www.quamus.org)."
PARSERS_HAZM_URI = "org.PersDigUMD:tools.hazm.v2"
PARSERS_HAZM_RIGHTS = "Morphology from the HAZM Analyzer (http://www.sobhe.ir/hazm) adapted by the Roshan Institute for Persian Studies at UMD (http://persdig.umd.edu) and the Perseus Digital Library at Tufts University (http://www.perseus.tufts.edu)."
PARSERS_ARAMORPH_REMOTE_URL = "http://alpheios.net/perl/aramorph2?word="
PARSERS_WHITAKERS_URI = "net.alpheios:tools:wordsxml.v1"
PARSERS_WHITAKERS_PATH = "/home/balmas/workspace/wordsxml/dist/Linux_x86-gcc4/wordsxml"
PARSERS_WHITAKERS_RIGHTS = "Short definitions and morphology from Words by William Whitaker, Copyright © 1993-2007."
SERVICES_LEXICAL_ENTITY_SVC_GRC = None
SERVICES_LEXICAL_ENTITY_SVC_LAT = None
SERVICES_LEXICAL_ENTITY_BASE_URI = None
5 changes: 2 additions & 3 deletions morphsvc/lib/engines/AlpheiosXmlEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ def __init__(self, code, config,**kwargs):
self.code = code
self.oa_transformer = OaLegacyTransformer()
self.uri = ""
self.rights = ""

def get_uri(self):
return self.uri

def as_annotation(self, annotation_uri, word_uri,analysis):
return self.oa_transformer.wrap(annotation_uri, word_uri, self.get_uri(), analysis)
return self.oa_transformer.wrap(annotation_uri, word_uri, self.get_uri(), analysis, self.rights)

def output_json(self, engine_response):
return dumps(legacy.data(engine_response),ensure_ascii=False)
Expand All @@ -31,5 +32,3 @@ def to_cache(self, engine_response):

def from_cache(self,cached_response):
return etree.fromstring(cached_response)


1 change: 1 addition & 0 deletions morphsvc/lib/engines/AramorphLegacyRemoteEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ def __init__(self,code, config,**kwargs):
self.language_codes = ['ara', 'ar']
self.config = config
self.uri = self.config['PARSERS_ARAMORPH_URI']
self.rights = self.config['PARSERS_ARAMORPH_RIGHTS']
self.remote_url = self.config['PARSERS_ARAMORPH_REMOTE_URL']
self.transformer = None
3 changes: 1 addition & 2 deletions morphsvc/lib/engines/AramorphRemoteEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def __init__(self,code, config,**kwargs):
self.language_codes = ['ara', 'ar']
self.config = config
self.uri = self.config['PARSERS_ARAMORPH_URI']
self.rights = self.config['PARSERS_ARAMORPH_RIGHTS']
self.remote_url = self.config['PARSERS_ARAMORPH_REMOTE_URL']
self.transformer = BuckwalterTransformer(config)


3 changes: 2 additions & 1 deletion morphsvc/lib/engines/HazmEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self,code, config,**kwargs):
self.oa_transformer = OaLegacyTransformer()
self.language_codes = ['per','fas']
self.uri = self.config['PARSERS_HAZM_URI']
self.rights = self.config['PARSERS_HAZM_RIGHTS']
self.tagger = POSTagger(model=os.path.join(os.path.dirname(__file__),'hazm',"postagger.model"))

def lookup(self,word=None,word_uri=None,language=None,request_args=None,**kwargs):
Expand Down Expand Up @@ -132,4 +133,4 @@ def entrytoxml(self,entry):
if (i['pofs'] and i['pofs']['text']):
pofs = etree.SubElement(infl, 'pofs', {'order': i['pofs']['order']})
pofs.text = i['pofs']['text']
return root
return root
1 change: 1 addition & 0 deletions morphsvc/lib/engines/MorpheusLegacyLocalEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self,code, config,**kwargs):
self.config = config
self.language_codes = ['grc']
self.uri = self.config['PARSERS_MORPHEUS_URI']
self.rights = self.config['PARSERS_MORPHEUS_RIGHTS']
self.morpheus_path = self.config['PARSERS_MORPHEUS_PATH']
self.transformer = AsciiGreekTransformer(config)

Expand Down
1 change: 1 addition & 0 deletions morphsvc/lib/engines/MorpheusLocalEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self,code, config,**kwargs):
self.config = config
self.language_codes = ['grc', 'la', 'lat' ]
self.uri = self.config['PARSERS_MORPHEUS_URI']
self.rights = self.config['PARSERS_MORPHEUS_RIGHTS']
self.morpheus_path = self.config['PARSERS_MORPHEUS_PATH']
self.transformer = BetacodeTransformer(config)
self.latin_transformer = LatinTransformer(config)
Expand Down
1 change: 1 addition & 0 deletions morphsvc/lib/engines/WhitakersLocalEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self,code, config,**kwargs):
self.language_codes = ['la', 'lat' ]
self.uri = self.config['PARSERS_WHITAKERS_URI']
self.wordsxml_path = self.config['PARSERS_WHITAKERS_PATH']
self.rights = self.config['PARSERS_WHITAKERS_RIGHTS']
self.latin_transformer = LatinTransformer(config)

def lookup(self,word=None,word_uri=None,language=None,request_args=None,**kwargs):
Expand Down
3 changes: 1 addition & 2 deletions morphsvc/lib/engines/WhitakersRemoteEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ def __init__(self,code,config,**kwargs):
self.config = config
self.uri = self.config['PARSERS_WHITAKERS_URI']
self.remote_url = self.config['PARSERS_WHITAKERS_REMOTE_URL']
self.rights = self.config['PARSERS_WHITAKERS_RIGHTS']
self.language_codes = ['lat','la']


9 changes: 5 additions & 4 deletions morphsvc/lib/transformers/OaLegacyTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ def __init__(self, *args,**kwargs):
xslt = pkg_resources.resource_string(resource_package,xslt_path)
self.xslt_transformer = etree.XSLT(etree.XML(xslt))

def wrap(self, annotation_uri, word_uri, engine_uri, xml):
def wrap(self, annotation_uri, word_uri, engine_uri, xml, engine_rights):
annotation_uri_param = etree.XSLT.strparam(annotation_uri)
word_uri_param = etree.XSLT.strparam(word_uri)
engine_uri_param = etree.XSLT.strparam(engine_uri)
engine_rights_param = etree.XSLT.strparam(engine_rights)
createdat_param = etree.XSLT.strparam(datetime.utcnow().isoformat())
transformed = self.xslt_transformer(xml,e_annotationuri = annotation_uri_param,
e_worduri = word_uri_param,
e_datetime = createdat_param, e_agenturi = engine_uri_param)
e_datetime = createdat_param,
e_agenturi = engine_uri_param,
e_agentrights= engine_rights_param)
return etree.fromstring(etree.tostring(transformed,encoding="unicode"))


24 changes: 14 additions & 10 deletions morphsvc/lib/transformers/xslt/wrap_oa_legacy.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,51 @@
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
version="1.0">

<!-- this template wraps a treebank annotation in an OA container.
parameters
parameters
e_datetime - the datetime of the serialization
e_collection - the urn of the CITE collection which the annotation is/will be a member of
e_docuri - target of the annotation, if supplied will override anything in the template
-->

<xsl:param name="e_datetime"/>
<xsl:param name="e_annotationuri"/>
<xsl:param name="e_worduri"/>
<xsl:param name="e_agenturi"/>

<xsl:param name="e_agentrights"/>

<xsl:output indent="yes" encoding="UTF-8"></xsl:output>
<xsl:strip-space elements="*"/>

<xsl:template match="/">

<xsl:element name="rdf:RDF">
<xsl:element name="oac:Annotation">
<xsl:attribute name="rdf:about"><xsl:value-of select="$e_annotationuri"/></xsl:attribute>
<xsl:element name="dcterms:creator">
<xsl:element name="foaf:Agent">
<xsl:attribute name="rdf:about"><xsl:value-of select="$e_agenturi"/></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:element>
<xsl:element name="dcterms:created">
<xsl:value-of select="$e_datetime"/>
</xsl:element>
<xsl:element name="dc:rights">
<xsl:value-of select="$e_agentrights"/>
</xsl:element>
<xsl:element name="oac:hasTarget">
<xsl:element name="rdf:Description">
<xsl:attribute name="rdf:about"><xsl:value-of select="$e_worduri"/></xsl:attribute>
</xsl:element>
</xsl:element>
<xsl:element name="dc:title"/>
<xsl:apply-templates select="//entry"></xsl:apply-templates>
<xsl:apply-templates select="//entry"></xsl:apply-templates>
</xsl:element>
</xsl:element>
</xsl:template>

<xsl:template match="entry">
<xsl:variable name="bodyid" select="concat('urn:uuid:',generate-id(.))"/>
<xsl:element name="oac:hasBody">
Expand Down

0 comments on commit 243408c

Please sign in to comment.