-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogrambkp
More file actions
171 lines (149 loc) · 6.72 KB
/
Copy pathprogrambkp
File metadata and controls
171 lines (149 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def process_phrase_in_query(self,phrase):
print "phrase is:"
print phrase
phrase_word_list=phrase.split()
processed_word_list=[]
if phrase_word_list[0]=="<grp>":
processed_word_list=phrase_word_list[1:]
else:
processed_word_list=phrase_word_list
print processed_word_list
print "phrase index instance"
print self.phrase_index_instance
if len(processed_word_list)==1:
if self.phrase_index_instance:
print "hello index"
print self.phrase_index_instance["1"]
return self.phrase_index_instance["1"]
else:
return self.return_query_results(phrase_word_list[0])
phrase_group=self.construct_phrase_groups(phrase_word_list)
print "group"
print phrase_group
group_counter=0
prev_phrase_group_document_list={}
# setting it to null because this has to contain entries for only the new groupings formed
print "group_keys"
print phrase_group.keys()
print "******"
for group in sorted(phrase_group.keys()):
relevant_doc_for_phrase={}
group_counter=group_counter+1
current_group=phrase_group[group]
print "group is %s" %group
if group_counter!=1:
print "Current group is"
print current_group
if prev_phrase_group_document_list:
print "processing group..."
relevant_doc_for_phrase=self.process_phrase_group(group,current_group,1)
prev_phrase_group_document_list=relevant_doc_for_phrase
self.phrase_index_instance.update(relevant_doc_for_phrase)
else:
self.phrase_index_instance={}
return self.phrase_index_instance
else:
print "Current group is"
print current_group
relevant_doc_for_phrase=self.process_phrase_group(group,current_group,1)
prev_phrase_group_document_list=relevant_doc_for_phrase
print "relavant phraase documents"
print relevant_doc_for_phrase
if relevant_doc_for_phrase == None:
return None
else:
self.phrase_index_instance.update(relevant_doc_for_phrase)
for key in sorted(self.phrase_index_instance.keys()):
if group_counter>=1:
if int(key) >group_counter:
del self.phrase_index_instance[key]
print "After invalidating the enteries"
print group_counter
print self.phrase_index_instance
group_counter=0
prev_grp_num=""
new_word="<grp> "
print "Grouping"
for group in sorted(self.phrase_index_instance.keys()):
print "group:%s" %group
print "^^^^^^^^^^^^^^^^"
hash1=self.phrase_index_instance[group]
for key in sorted(hash1.keys()):
print key
print hash1[key]
for group in sorted(self.phrase_index_instance.keys()):
new_word=new_word+" "+str(group)
print "new words"
print new_word
self.process_phrase_in_query(new_word)
print "returning from the method"
print self.phrase_index_instance
return self.phrase_index_instance["1"]
def process_phrase_group(self,group_number,phrase_group,distance,):
print "good group number is %s" %group_number
relevant_documents={}
match_count=0
word_1_hash={}
word_2_hash={}
is_word_1_grp=0
is_word_2_grp=0
if phrase_group:
if self.phrase_index_instance.has_key(phrase_group[0]):
is_word_1_grp=1
word_1_hash=self.phrase_index_instance[phrase_group[0] ]
else:
word_1_hash=self.return_query_results(phrase_group[0])
if len(phrase_group)==1:
relevant_documents.update({group_number:word_1_hash})
return relevant_documents
if self.phrase_index_instance.has_key(phrase_group[1]):
is_word_2_grp=1
word_2_hash=self.phrase_index_instance[phrase_group[1] ]
else:
word_2_hash=self.return_query_results(phrase_group[1])
print "words are:"
print phrase_group[0]
print phrase_group[1]
print "word1hash"
print word_1_hash
print "word2 hash"
print word_2_hash
common_documents_list=(set(word_1_hash)).intersection(set(word_2_hash))
print "common documents are "
print common_documents_list
if common_documents_list:
for document in common_documents_list:
match_count=0
match_positions=[]
for position1 in word_1_hash[document][1:] :
for position2 in word_2_hash[document][1:] :
check_distance=0
if is_word_1_grp==0 or is_word_2_grp==0:
print "setting check distance %d" %distance
check_distance=distance
else:
check_distance=2
if position1-position2==check_distance:
match_count=match_count+1
print match_count
if self.grouping_iteration>1 &&
match_positions.append(position2)
print match_positions
if match_count>=1:
print "match count"
print match_count
position_array=[match_count]
position_array.extend(match_positions)
print position_array
new_position={document:position_array}
if relevant_documents.has_key(group_number):
relevant_documents[group_number].update(new_position)
else:
relevant_documents.update({group_number:new_position})
else:
print group_number
print relevant_documents
return None
print "relavant documents"
print relevant_documents
return relevant_documents