Commit ffce454b authored by zehe's avatar zehe
Browse files

removed development folder

parent 49447e32
Pipeline #43298 passed with stage
in 12 seconds
import functools
import sys
def UIMAProperty(feature, override_getter: bool=True, override_setter: bool=True):
class _MyDecorator:
def __init__(self, func, setter=None):
self.__getter = func
self.__setter = setter
self.__name__ = func.__name__
#def __set_name__(self, owner, name):
# setattr(owner, name, property(self.func))
# owner.feature_name_mapping[name] = [feature, override_getter, override_setter]
def __get__(self, instance, owner):
if instance is None:
return self
owner.feature_name_mapping[self.__name__] = [feature, override_getter, override_setter]
return self.__getter(instance)
def __set__(self, instance, value):
if self.__setter is None:
raise AttributeError(f'{self.__name__} is read-only')
return self.__setter(instance, value)
def setter(self, setter):
self.__setter = setter
return self
return _MyDecorator
class UIMAToken:
uima_type = "de.uniwue.wuenlp.Token"
new_var = 5
feature_name_mapping = dict()
@UIMAProperty('RFTag', False, False)
def rf_tag(self):
return self.new_var
@rf_tag.setter
def rf_tag(self, x):
self.new_var = x
x = UIMAToken()
#x.rf_tag = 13
#print(x.rf_tag)
#print(x.feature_name_mapping)
print(x.rf_tag)
#x.rf_tag()
print(x.feature_name_mapping)
x.rf_tag = 10
print(x.rf_tag)
This diff is collapsed.
import inspect
import sys
from typing import Type
from wuenlp.base.NLPStructs import BaseFeatureStructure
from wuenlp.impl import UIMANLPStructs
from wuenlp.impl.UIMANLPStructs import UIMAAnnotation, UIMASpan
from uima.Typesystem import TypeSystem
def get_typesystem():
ts = TypeSystem.from_path(XML_FILE)
result = [x for x in ts.types if x.supertypeName is not None and x.supertypeName != 'uima.tcas.Annotation' and x.supertypeName != 'uima.cas.TOP' and not x.name.startswith('uima.')]
for res in result:
feat = [x.name for x in res.features]
print(res.name, feat)
return result
def get_classes():
uima_types = inspect.getmembers(UIMANLPStructs)
uima_classes = []
for uname, utype in uima_types:
if inspect.isclass(utype) and 'uima_type' in utype.__dict__ and utype.uima_type != 'uima.tcas.Annotation':
uima_classes.append(utype)
for x in uima_classes:
print(x.uima_type, x.feature_name_mapping)
return uima_classes
def compare_types_and_classes(tps, css):
# check if all types in uima_classes
print('Checking Typesystems')
for tp in tps:
if tp not in css:
print(tp)
# check if all classes in types
print('Checking Classes')
for cs in css:
if cs not in tps:
print(cs)
print(all(elem in css for elem in tps))
print(all(elem in tps for elem in css))
def main():
uima_types = inspect.getmembers(UIMANLPStructs)
for uname, utype in uima_types:
if inspect.isclass(utype) and 'uima_type' in utype.__dict__ and utype.uima_type != 'uima.tcas.Annotation':
print(uname, utype)
#print(utype.__bases__)
attribs = dict()
for base in utype.__bases__:
for k, v in inspect.getmembers(base):
if k not in attribs.keys():
attribs[k] = v
for k, v in inspect.getmembers(utype):
if not k.startswith('__') and not k.startswith('_'):
if k not in attribs or v != attribs[k]:
print(k, v)
print()
if __name__ == '__main__':
XML_FILE = '../wuenlp/resources/WueNLPTypesystem.xml'
# main()
#get_typesystem()
get_classes()
#for x in ts:
# print(x)
import sys
class UIMAToken:
uima_type = "de.uniwue.wuenlp.Token"
feature_name_mapping = {
'rf_tag': ['RFTag', 'string'],
'pos_fine': ['POSTagFine'],
'stem': ['Stem'],
'pos': ['POSTag'],
'lemma': ['Lemma'],
'dependency_head': ['DependencyHead'],
'dependency_relation': ['DependencyRelation']
}
def add_feature_function(pclass, pname, pfeature):
fn_name = pname
def fn_getter(self):
# return self.anno[pfeature]
return self._x
def fn_setter(self, value):
# self._set_feature_value(pfeature, value)
self._x = value
print(f"set value on {self} to {value}")
setattr(pclass, fn_name, property(fn_getter, fn_setter))
clist = ['UIMAToken']
for cname in clist:
cobj = getattr(sys.modules[__name__], cname)
for k, v in cobj.feature_name_mapping.items():
add_feature_function(cobj, k, v[0])
x = UIMAToken()
x.rf_tag = 13
print(x.rf_tag)
import sys
class UIMAToken:
uima_type = "de.uniwue.wuenlp.Token"
feature_name_mapping = {
'rf_tag': ['RFTag', 'string'],
'pos_fine': ['POSTagFine'],
'stem': ['Stem'],
'pos': ['POSTag'],
'lemma': ['Lemma'],
'dependency_head': ['DependencyHead'],
'dependency_relation': ['DependencyRelation']
}
@classmethod
def add_feature_function(cls, pname, pfeature):
fn_name = pname
def fn_getter(self):
# return self.anno[pfeature]
return self._x
def fn_setter(self, value):
# self._set_feature_value(pfeature, value)
self._x = value
print(f"set value on {self} to {value}")
setattr(cls, fn_name, property(fn_getter, fn_setter))
def __init__(self):
for k, v in self.feature_name_mapping.items():
self.add_feature_function(k, v[0])
x = UIMAToken()
x.rf_tag = 13
print(x.rf_tag)
......@@ -4,7 +4,7 @@ setup(
name='WueNLP', # How you named your package folder (MyLib)
packages=find_packages() + ["wuenlp/resources"], # Chose the same as "name"
package_data={"": ["WueNLPTypesystem.xml"]},
version='0.2.2', # Start with a small number and increase it with every change you make
version='0.2.3', # Start with a small number and increase it with every change you make
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
description='NLP Pipeline and utilities from Uni Würzburg', # Give a short description about your library
author='Markus Krug, Albin Zehe', # Type in your name
......@@ -18,7 +18,7 @@ setup(
"spacy",
"sfst",
"loguru",
"pyuima @ git+https://gitlab2.informatik.uni-wuerzburg.de/alz20ij/PyUIMA.git"
"pyuima @ git+https://gitlab2.informatik.uni-wuerzburg.de/alz20ij/PyUIMA.git",
],
classifiers=[
'Development Status :: 3 - Alpha',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment