From 882911ef23c33019d52ed19e8581c2e560a076cd Mon Sep 17 00:00:00 2001 From: Olcay Taner YILDIZ Date: Thu, 1 Jul 2021 19:42:35 +0300 Subject: [PATCH] Added ccg layer to AnnotatedWord --- AnnotatedSentence/AnnotatedWord.py | 42 +++++++++++++++++++++++++++++- AnnotatedSentence/ViewLayerType.py | 1 + setup.py | 2 +- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/AnnotatedSentence/AnnotatedWord.py b/AnnotatedSentence/AnnotatedWord.py index 9eb791b..c90748a 100644 --- a/AnnotatedSentence/AnnotatedWord.py +++ b/AnnotatedSentence/AnnotatedWord.py @@ -18,6 +18,17 @@ class AnnotatedWord(Word): + """ + * In order to add another layer, do the following: + * 1. Select a name for the layer. + * 2. Add a new constant to ViewLayerType. + * 3. Add private attribute. + * 4. Add an if-else to the constructor, where you set the private attribute with the layer name. + * 5. Update toString method. + * 6. Add initial value to the private attribute in other constructors. + * 7. Update getLayerInfo. + * 8. Add getter and setter methods. + """ __parse: MorphologicalParse __metamorphicParse: MetamorphicParse __semantic: str @@ -28,7 +39,7 @@ class AnnotatedWord(Word): __universalDependency: UniversalDependencyRelation __slot: Slot __polarity: PolarityType - + __ccg: str def __init__(self, word: str, layerType=None): """ @@ -50,6 +61,7 @@ def __init__(self, word: str, layerType=None): self.__universalDependency = None self.__slot = None self.__polarity = None + self.__ccg = None if layerType is None: splitLayers = re.compile("[{}]").split(word) for layer in splitLayers: @@ -83,6 +95,8 @@ def __init__(self, word: str, layerType=None): elif layerType == "universalDependency": values = layerValue.split("$") self.__universalDependency = UniversalDependencyRelation(int(values[0]), values[1]) + elif layerType == "ccg": + self.__ccg = layerValue elif isinstance(layerType, NamedEntityType): super().__init__(word) self.__namedEntityType = layerType @@ -131,6 +145,8 @@ def __str__(self) -> str: if self.__universalDependency is not None: result = result + "{universalDependency=" + self.__universalDependency.to().__str__() + "$" + \ self.__universalDependency.__str__() + "}" + if self.__ccg is not None: + result = result + "{ccg=" + self.__ccg + "}" return result def getLayerInfo(self, viewLayerType: ViewLayerType) -> str: @@ -177,6 +193,8 @@ def getLayerInfo(self, viewLayerType: ViewLayerType) -> str: elif viewLayerType == ViewLayerType.DEPENDENCY: if self.__universalDependency is not None: return self.__universalDependency.to().__str__() + "$" + self.__universalDependency.__str__() + elif viewLayerType == ViewLayerType.CCG: + return self.__ccg else: return None @@ -419,6 +437,28 @@ def setShallowParse(self, parse: str): """ self.__shallowParse = parse + def getCcg(self) -> str: + """ + Returns the ccg layer of the word. + + RETURNS + ------- + str + Ccg tag of the word. + """ + return self.__ccg + + def setCcg(self, ccg: str): + """ + Sets the ccg layer of the word. + + PARAMETERS + ---------- + parse : str + New ccg tag of the word. + """ + self.__ccg = ccg + def getUniversalDependency(self) -> UniversalDependencyRelation: """ Returns the universal dependency layer of the word. diff --git a/AnnotatedSentence/ViewLayerType.py b/AnnotatedSentence/ViewLayerType.py index 6017975..b846e3e 100644 --- a/AnnotatedSentence/ViewLayerType.py +++ b/AnnotatedSentence/ViewLayerType.py @@ -25,3 +25,4 @@ class ViewLayerType(Enum): FRAMENET = auto() SLOT = auto() POLARITY = auto() + CCG = auto() diff --git a/setup.py b/setup.py index d4a71c2..05dfc4b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='NlpToolkit-AnnotatedSentence', - version='1.0.28', + version='1.0.29', packages=['AnnotatedSentence'], url='https://github.com/olcaytaner/AnnotatedSentence-Py', license='',