Finding Semantic Coherence between sentences in a text

1.5k Views Asked by At

I need some help writing a program based on the code from these links link1 and link2 that will automatically calculate the semantic similarity between a. Consecutive sentences and b. Sentences seperates by 1 intervening phrase, in and entire document (1000 sentences).

The provided code already tokenizes and can find semantic similarity but I have no clue how to write the new code that will calculate (and display) the semantic similarity between consecutive and "intervening" sentences across the whole text (a,b).I don't want to do the same thing over and over again.

1

There are 1 best solutions below

2
On

The following code should do what you want, adjust it depending on how you want the output formatted.

with open("sentence_file_name", "r") as sentence_file:
    while x and y:
    x = sentence_file.readline()
    y = sentence_file.readline()
    similarity(x, y, boolean) #boolean set to false or true depending on what you want
    x = y
    y = sentence_file.readline()