简体   繁体   中英

Finding Semantic Coherence between sentences in a text

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.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM