123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- #! /usr/bin/python
- # -*- coding: utf-8 -*-
- """
- This module defines classes related to SPMRL constituency and dependency
- annotation format.
-
- Version 1.0 (02-Jun-2015)
- - SPMRLConstTree and SPMRLConstNode are added.
- """
- import constparse
- #¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
- # SPMRLConstTree
- #¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
- class SPMRLConstTree(constparse.ConstTree):
- '''
- Class for SPMRL-format constituency tree
- '''
-
- def __init__(self):
- '''
- Constructor
- '''
-
- constparse.ConstTree.__init__(self)
-
-
-
- def _createRoot(self):
- '''
- Creates and returns the root node
- '''
-
- return SPMRLConstNode()
-
-
-
- def removeFeatures(self):
- '''
- Removes feature annotation from the syntactic label.
-
- Feature annotations are surrounded by ## and follow the syntactic
- label (e.g. (CLS-SUJ##lem=il|cpos=CL|g=m|n=p|p=1|s=suj## Nous)).
- '''
-
- self.root.removeFeatures(pflgAllSubtree = True)
-
-
-
- #¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
- # SPMRLConstNode
- #¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
- class SPMRLConstNode(constparse.ConstNode):
- '''
- Class for SPMRL-format constituency tree node
- '''
-
- def __init__(self):
- '''
- Constructor
- '''
-
- constparse.ConstNode.__init__(self)
-
-
-
- def _getNewNode(self):
- '''
- Creates and returns a node
- '''
-
- return SPMRLConstNode()
-
-
-
- def getFeatures(self):
- '''
- Returns the feature annotation attached to the label
- '''
-
- vGluePos = self.getLabel().find('##')
-
- if vGluePos != -1:
- return self.getLabel()[vGluePos + 2 : -2]
- else:
- return ''
-
-
-
- def removeFeatures(self, pflgAllSubtree = False):
- '''
- Removes feature annotation from the syntactic label.
-
- Feature annotations are surrounded by ## and follow the syntactic
- label (e.g. (CLS-SUJ##lem=il|cpos=CL|g=m|n=p|p=1|s=suj## Nous)).
-
- The removal can be done to only the current node or the entire subtree
- under the node.
- '''
-
- vGluePos = self.getLabel().find('##')
-
- if vGluePos != -1:
- self.synTag = self.getLabel()[ : vGluePos]
-
- if pflgAllSubtree:
- for vChild in self.getChildren():
- vChild.removeFeatures(pflgAllSubtree = pflgAllSubtree)
-
-
-
- #¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
- # SPMRLConstParseLoader
- #¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
- class SPMRLConstParseLoader(constparse.ConstParseLoader):
- '''
- Constituency parse loader
-
- see the parent class for details
- '''
-
- def __init__(self):
- '''
- Constructor
- '''
-
- # list of ConstParses
- self.parses = None
-
-
-
- def _createNewTree(self):
- '''
- Creates and returns a new constituency tree
- '''
-
- return SPMRLConstTree()
-
-
-
|