Skip to content

Commit

Permalink
changed graph centrality prior, added sentence position prior
Browse files Browse the repository at this point in the history
  • Loading branch information
GoncaloKLopes committed Dec 7, 2017
1 parent 54c6c58 commit 73327dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ex2/2.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def build_summary(sentences,prior_func,weight_func,t):
with open(source_path + text_file,'r',encoding='Latin-1') as file: #source_path + text_file
text = file.read()
sentences = text_to_sentences(text)
summary = build_summary(sentences,uniform_prior,cos_sim_weight,thresh)
summary = build_summary(sentences,uniform_prior,uniform_weight,thresh)
with open(source_path + text_file,'r',encoding='Latin-1') as summary_file: #sums_path+ 'Ext-' + text_file '../ex1/textsum.txt'
MAP += AP(summary,summary_file.read())
#print(MAP)
Expand Down
20 changes: 17 additions & 3 deletions ex2/priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ def uniform_prior(sent_index,graph,sentences):

#receives graph matrix for convenience...
def degree_centrality_prior(sent_index,graph,sentences):
links = graph[sent_index]
nonzero = np.nonzero(links)[0]
return len(nonzero)/len(links)
total_links = 0
degree = 0
for i in range(len(graph)):
nonzeros = len(np.nonzero(graph[i])[0])
if i == sent_index:
degree = nonzeros
total_links += nonzeros
if total_links == 0:
return 0
return degree/total_links


def sentence_position_prior(sent_index,graph,sentences):
total = 0
for i in range(len(sentences)):
total += 1
return (sent_index + 1) / total
2 changes: 1 addition & 1 deletion functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def AP(systemSummaries, targetSummaries):

#sentences is a list, returns cossim matrix
def get_cosine_similarities_matrix(sentences):
vec = TfidfVectorizer()
vec = TfidfVectorizer(stop_words='english')

X = vec.fit_transform(sentences)
return cosine_similarity(X)
Expand Down

0 comments on commit 73327dd

Please sign in to comment.