Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed unused code, added comments.

  • Loading branch information...
commit a5da7465f60c9193c62352b6832957838ecf01d8 1 parent ecc91c0
julosaure authored

Showing 1 changed file with 14 additions and 42 deletions. Show diff stats Hide diff stats

  1. +14 42 multiAligner.py
56 multiAligner.py
@@ -23,7 +23,7 @@ def align(self):
23 23 lAlign = copy.copy(lNumSentence)
24 24
25 25 while len(lAlign) > 1:
26   - distMat = self.computeDistanceMatrix2(lAlign)
  26 + distMat = self.computeDistanceMatrix(lAlign)
27 27 print distMat
28 28 i1, i2 = self.pickItemsToAlign(distMat, lAlign)
29 29 a2 = lAlign.pop(i2)
@@ -38,6 +38,8 @@ def align(self):
38 38 return align, alignstr
39 39
40 40 def pickItemsToAlign(self, distMat, lAlign):
  41 + """ Finds a pair of Sentence and/or Alignments whose distance is minimal.
  42 + """
41 43 minVal = 999
42 44 minI = 0
43 45 minJ = 0
@@ -49,7 +51,9 @@ def pickItemsToAlign(self, distMat, lAlign):
49 51 minJ = j
50 52 return minI, minJ
51 53
52   - def computeDistanceMatrix2(self, lAlign):
  54 + def computeDistanceMatrix(self, lAlign):
  55 + """ Computes the distance matrix between all Sentence and Alignments.
  56 + """
53 57 nbSentence = len(lAlign)
54 58 distMat = numpy.zeros((nbSentence, nbSentence), int)
55 59
@@ -63,35 +67,9 @@ def computeDistanceMatrix2(self, lAlign):
63 67 return distMat
64 68
65 69
66   - def pickSentencePair(self, distMat, sentencesToAlign):
67   - """ Pick the sentence pair with minimal edit distance in distMat.
68   - """
69   - minVal = 999
70   - minI = 0
71   - minJ = 0
72   - for i in xrange(len(sentencesToAlign)):
73   - for j in xrange(i+1, len(sentencesToAlign)):
74   - if distMat[i,j] < minVal:
75   - minVal = distMat[i,j]
76   - minI = i
77   - minJ = j
78   - return minI, minJ
79   -
80   - def pickMinSentence(self, distMat, sentencesToAlign, lAlignedSentences):
81   - """ Pick the sentence with minimal edit distance to previously aligned sentences.
82   - """
83   - minVal = 999
84   - minJ = 0
85   - for i in lAlignedSentences:
86   - for j in xrange(len(sentencesToAlign)):
87   - if j in lAlignedSentences:
88   - continue
89   - if distMat[i,j] < minVal:
90   - minVal = distMat[i,j]
91   - minJ = j
92   - return minJ
93   -
94 70 def alignItems(self, a1, a2, sentencesToAlign):
  71 + """ Aligns 2 items, either Sentence or Alignment.
  72 + """
95 73 if isinstance(a1, tuple) and isinstance(a2, tuple):
96 74 print a1
97 75 print a2
@@ -109,6 +87,8 @@ def alignItems(self, a1, a2, sentencesToAlign):
109 87 return align
110 88
111 89 def alignAlignments(self, a1, a2):
  90 + """Aligns 2 Alignment.
  91 + """
112 92 finalCell = self.computeEditDistance(a1, a2)
113 93 #print editMat
114 94
@@ -164,6 +144,8 @@ def alignAlignments(self, a1, a2):
164 144
165 145
166 146 def alignSentenceVsAlignment(self, a1, a2):
  147 + """Aligns an Alignment and a Sentence.
  148 + """
167 149 n2, s2 = a2 #align.lSentence[n2]
168 150 #print s2
169 151 finalCell = self.computeEditDistance(a1, s2)
@@ -213,6 +195,8 @@ def alignSentenceVsAlignment(self, a1, a2):
213 195
214 196
215 197 def alignSentencePair(self, a1, a2, sentencesToAlign):
  198 + """ Aligns 2 Sentence.
  199 + """
216 200 n1, s1 = a1 #sentencesToAlign[n1]
217 201 n2, s2 = a2 #sentencesToAlign[n2]
218 202 finalCell = self.computeEditDistance(s1, s2)
@@ -246,18 +230,6 @@ def alignSentencePair(self, a1, a2, sentencesToAlign):
246 230 align.alignedSentences.extend([n1, n2])
247 231 return align
248 232
249   - def computeDistanceMatrix(self, sentenceToAlign):
250   - """ Compute the matrix of edit distance between all pairs of items (Sentence or Alignment) of sentencesToAlign.
251   - """
252   - nbSentence = len(sentenceToAlign)
253   - distMat = numpy.zeros((nbSentence, nbSentence), int)
254   -
255   - for i in xrange(len(sentenceToAlign)):
256   - for j in xrange(i+1, len(sentenceToAlign)):
257   - editMat, finalCell = self.computeEditDistance(sentenceToAlign[i], sentenceToAlign[j])
258   - distMat[i,j] = finalCell.val
259   - return distMat
260   -
261 233 @memo
262 234 def computeEditDistance(self, s1, s2):
263 235 """ Compute the edit distance betweem to items, either Sentences or Alignments.

0 comments on commit a5da746

Please sign in to comment.
Something went wrong with that request. Please try again.