QBoard » Artificial Intelligence & ML » AI and ML - Others » how find the connecting words in text analysis in python?

how find the connecting words in text analysis in python?

  • I wanted to check the connection between 2 words in text analytics in python.currently using NLTK package in python.

    For example "Text = "There are thousands of types of specific networks proposed by researchers as modifications or tweaks to existing models"

    here if i input as networks and researchers, then i should get output as "Proposed by" or "networks proposed by researchers"
      August 6, 2020 3:43 PM IST
    0
    • Biswajeet  Dasmajumdar
      Biswajeet Dasmajumdar more advanced approach, using a neural language model, is to use Long Short Term Memory (LSTM). LSTM model uses Deep learning with a network of artificial “cells” that manage memory, making them better suited for text prediction than traditional neural neteorks
      October 7, 2020
  • You could Regex match between the two words
    import re
    
    word_one = "networks"
    word_two = "researchers"
    
    string = "There are thousands of types of specific networks proposed by researchers as modifications or tweaks to existing models"
    
    result = re.search(f'{word_one}(.+?){word_two}', string)
    print(result.group(1))​
      August 6, 2020 3:45 PM IST
    0
  • Tom's answer is cleaner. Here is my answer without additional libraries

    Find the locations of each word, then use those locations to extract it

    text = "There are thousands of types of specific networks proposed by researchers as modifications or tweaks to existing models"
    
    word1 = "networks"
    word2 = "researchers"
    
    start = text.find(word1)
    end = text.find(word2)
    
    if start != -1 and end != -1 and start < end:
        print(text[start + len(word1):end])
      October 20, 2021 12:51 PM IST
    0
  • Rakesh's answer is cleaner. Here is my answer without additional libraries

    Find the locations of each word, then use those locations to extract it.

    text = "There are thousands of types of specific networks proposed by researchers as modifications or tweaks to existing models"
    
    word1 = "networks"
    word2 = "researchers"
    
    start = text.find(word1)
    end = text.find(word2)
    
    if start != -1 and end != -1 and start < end:
        print(text[start + len(word1):end])

     

      December 28, 2020 12:09 PM IST
    0