Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1.     def match(self, node):
  2.         # Find entities that do not have a node spanning them
  3.         word = node.child(0)
  4.         if not word.isLeaf():
  5.             return False
  6.         print 'word: %s' % word
  7.         ### Get an entity:
  8.         if not word.entity.startswith('B-'):
  9.             return False
  10.         entity_type = word.entity[2:]
  11.         print 'entity_type: %s' % entity_type
  12.         print 'Finding root node: %s' % word
  13.         while not node.isRoot():
  14.             print 'node.label in while loop: %s, %s' % (node.label, node)
  15.             if node.isEntity(entity_type):
  16.                 print 'node %s is an entity' % word
  17.                 print 'returning false'
  18.                 return False
  19.             node = node.parent()
  20.        
  21.         entity_words = self._getSpan(word)
  22.         print 'entity_words: %s' % ([w.text for w in entity_words])
  23.         last_word = entity_words[-1]
  24.         print 'last_word: %s' % last_word
  25.         last_word_node = last_word.parent()
  26.         print 'last_word_node: %s' % last_word_node
  27.         sibling = last_word_node.sibling()
  28.         print 'sibling: %s' % sibling
  29.        
  30.        
  31.         if not sibling:
  32.             return False
  33.         if not sibling.label.is_adjunct:
  34.             return False
  35.         modifier = sibling.getWord(0)
  36.         if modifier.label != 'IN':
  37.             return False
  38.        
  39.         print '\n<working1>'
  40.         ### for all the nodes in the entity under entity_root, if there exists a sibling node
  41.         ### which is not part of the entity, there's a problem...
  42.         ### Check siblings of all words in the entity:
  43.         ### first, get parent of first leaf node that is an entity - what we just found
  44.         entity_root = word.parent().parent()
  45.         print 'entity_root: %s' % entity_root
  46.         entity_nodes = entity_root.depthList()
  47.         print 'entity_nodes:'
  48.         for i in entity_nodes:
  49.             if i.isLeaf() and not i.entity:
  50.                 print 'not an entity???'
  51.                 return True
  52.         print '</working1>\n'
  53.         return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement