Skip to content

Commit

Permalink
findNeighborhoodSimilarities function for textual neighborhood simila…
Browse files Browse the repository at this point in the history
…rity added
  • Loading branch information
rameshjes committed Nov 16, 2017
1 parent e7b9c1d commit 598312a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion monolingualWordAligner/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from config import *

class Util:


Expand Down Expand Up @@ -257,4 +259,28 @@ def findChildren(self, dependencies, wordIndex, word):
childrenWithRelation.append(child)
break

return childrenWithRelation
return childrenWithRelation


'''
Returns words withn (3,3) neighborhood window
'''

def findNeighborhoodSimilarities(self, sentenceDetails, wordIndex, leftSpan, rightSpan):


lemmas = []
wordIndices = []
sentenceLen = len(sentenceDetails)
startWordIndex = max(1, wordIndex - rightSpan)
endWordIndex = min(sentenceLen, wordIndex+rightSpan)
for item in sentenceDetails[startWordIndex-1:wordIndex-1]:
if item[3] not in stopwords + punctuations:
lemmas.append(item[3])
wordIndices.append(item[1])
for item in sentenceDetails[wordIndex:endWordIndex]:
if item[3] not in stopwords + punctuations:
lemmas.append(item[3])
wordIndices.append(item[1])

return [wordIndices, lemmas, wordIndex-startWordIndex, endWordIndex-wordIndex]

0 comments on commit 598312a

Please sign in to comment.