Skip to content

Commit

Permalink
Added ccg layer to AnnotatedWord
Browse files Browse the repository at this point in the history
  • Loading branch information
Olcay Taner YILDIZ committed Jul 1, 2021
1 parent b14b7fd commit 882911e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
42 changes: 41 additions & 1 deletion AnnotatedSentence/AnnotatedWord.py
Expand Up @@ -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
Expand All @@ -28,7 +39,7 @@ class AnnotatedWord(Word):
__universalDependency: UniversalDependencyRelation
__slot: Slot
__polarity: PolarityType

__ccg: str

def __init__(self, word: str, layerType=None):
"""
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions AnnotatedSentence/ViewLayerType.py
Expand Up @@ -25,3 +25,4 @@ class ViewLayerType(Enum):
FRAMENET = auto()
SLOT = auto()
POLARITY = auto()
CCG = auto()
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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='',
Expand Down

0 comments on commit 882911e

Please sign in to comment.