DerwenAI / pytextrank

Python implementation of TextRank algorithms ("textgraphs") for phrase extraction
https://derwen.ai/docs/ptr/
MIT License
2.15k stars 333 forks source link

KeyError: 'graf' #8

Closed ptynecki closed 7 years ago

ptynecki commented 7 years ago

Hi guys,

I'd like to use pytextrank for keywords extraction from single sentences (questions).

After the installation and downloading a language model I ran pytextrank in IPython with success.

Next, I decided to ran Stage 2 from your example.ipynb with normalize_key_phrases feature.

After that I received KeyError: 'graf' exception.

Details:

In [4]: graph, ranks = pytextrank.text_rank('mih.json')
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-4-ce8762751470> in <module>()
----> 1 graph, ranks = pytextrank.text_rank('mih.json')

/Users/katharsis/workspace/keywords_extractor/src/pytextrank.pyc in text_rank(path)
    349     run the TextRank algorithm
    350     """
--> 351     graph = build_graph(json_iter(path))
    352     ranks = nx.pagerank(graph)
    353

/Users/katharsis/workspace/keywords_extractor/src/pytextrank.pyc in build_graph(json_iter)
    299         print meta.keys()
    300
--> 301         for pair in get_tiles(map(WordNode._make, meta["graf"])):
    302             if DEBUG:
    303                 print(pair)

KeyError: 'graf'

I saw that mih.json not contains "graf" key. It includes "id" and "text" only. Is it related somehow?

PS. I'm using Python 2.7 on Mac OSx.

ceteri commented 7 years ago

Thank you for feedback @Katharsis -- did you run the "Stage 1" example first? Output from "Stage 1" is used as input for "Stage 2".

I did find an error in the notebook, but in a later step. Am committing that update now.

ptynecki commented 7 years ago

Stage 1 worked.

But I am interesting only about keywords extraction from the question. Would you like to insert this kind of example in your notebook? On input question / sentence example, but as an output extracted keywords with scoring values.

ptynecki commented 7 years ago

@ceteri

We can close that issue. The example works now.

AshwiniPatil5 commented 6 years ago

@Katharsis : Could you please tell me the input json format for the stage1.py. I have documents in text(.txt) format. Trying to extract key phrases as output with this tool. So if you could tell how to pass the sentences or the list of sentenses as input for this tool it would be of great help. Thanks in advance.