如何根据书的段落创建思维导图

l0k*_*ndr 5 c++ algorithm graph dot

今天我尝试编写一个程序,该程序将接受一段文本并创建一个显示不同单词之间关系的图表.一切顺利,除了我不知道如何以更好的方式找到联系.更好的方式意味着类似于思维导图.这是一个简单的输入,但我想创建一个程序,可以从维基百科中获取一个段落,并给出一个非常好的思维导图.我从以下输入的程序的点格式输出中得到的图表是

roses are red line_end
sky is blue line_end
life is beautiful line_end
everything is going fine line_end file_end
Run Code Online (Sandbox Code Playgroud)

graphviz输出

但是对于像这个输入这样的输入,它只是创建了一个非常大的图形,它比文本本身更加模糊.

Probability is a measure of the likeliness that an event will occur line_end
Probability is used to quantify an attitude of mind towards some proposition of    whose truth we are not certain line_end
file_end
Run Code Online (Sandbox Code Playgroud)

第二个输出,非常模糊

所以我的问题是,在这种情况下,什么算法可以正常工作.我应该学习什么才能制作这样的节目.下面是我的C++程序.(我还使用ruby进行文本处理,以"line_end"和"file_end"获取当前形式的段落,但这不是我遇到问题的地方)

  #include<iostream>
  #include<algorithm>
  #include<vector>
  #include<set>
  #include<map>
  #include<string>
  #define MP(X,Y)  (make_pair<string,string>(X,Y))

  using namespace std;
  map<string, vector<string> > mind_map;
  set<string> ignore_these_words;
  set<pair<string,string> > already_discovered;

  string black_list[] = {"and","is","are","was","for","the","a","an","or","under","up","over","beside","below",
            "across","to","from","by","have","had","has","been","be","it","me","you"};
  vector<string> current_sentence;


  int main()
  {
    for(int i =0; i<(sizeof(black_list)/sizeof(black_list[0])) ; i++)
            ignore_these_words.insert(black_list[i] );


    while(1)
    {
    string input_word;
    cin >> input_word;

    if( ignore_these_words.find(input_word) != ignore_these_words.end() )
        continue;

    /* if  the sentence end has been reached, then insert all pairs of combinations  of words in the graph
       for example if the sentence is "roses are red and beautiful", then it will try to insert the following pairs of edges
       after ignoring "are" and "and" from the ignore list
       (roses,red)
       (roses,beautiful)
       (red,beautiful)
    */


    if(input_word == "line_end")
    {
        for(int i =0; i< current_sentence.size() ; i++)
            for(int j = i+1; j < current_sentence.size(); j++)
                /* if we have not discovered this connection earlier */
                if( already_discovered.find( MP(current_sentence[i],current_sentence[j]) ) == already_discovered.end() )
                    {
                        mind_map[current_sentence[i]].push_back( current_sentence[j]);
                        already_discovered.insert(MP(current_sentence[i],current_sentence[j]) );
                        already_discovered.insert(MP(current_sentence[j],current_sentence[i] ) );
                    }
        current_sentence.clear();
        continue;
    }


    /* if the file end has been reached, then output the graph in dot format */
     if( input_word == "file_end")
    {
        cout << "graph {"<<endl;
        for( map<string,vector<string> >::iterator it = mind_map.begin(); it != mind_map.end(); ++it)
            for( int i =0; i< (*it).second.size(); i++)
                cout<<"\""<<(*it).first<<"\""<<" -- "<<"\""<<(*it).second[i]<<"\""<<endl;
        cout<< "}"<<endl;
        break;
    }


    current_sentence.push_back(input_word);
    }
    return 0;
  }
Run Code Online (Sandbox Code Playgroud)

在此先感谢:).如果有人有这样的代码,请给我.我想通过这个让我的学习更有成效.

Bre*_*ldt 0

虽然对待像互联网这样的语言可能有点粗鲁,但我相信PageRank(由 Google 搜索引擎使用)与您正在尝试做的事情有一些重要的相似之处(创建一个显示相对重要性的地图)。

Google 的 PageRank 是基于给予每个网站相对的“重要性”。因此,当网站 A 具有到网站 B 的链接时,B 就会获得相对于 A 重要性的“重要性”。例如,当一个无名网站链接到维基百科时,维基百科的重要性会小幅提升,但如果维基百科提供到另一个网站的链接,那么该网站就会因为维基百科的重要性而变得更加重要。PageRank 还有很多细微差别,但这只是一种体验。

类似地,为链接词分配“方向”就像一个网站链接到另一个网站:“A is B”是A“链接”到B。人们可以说“roses are red”就像“roses”重视“red” 。由于很多东西“都是红色的”,“红色”这个词就会获得很大的“重要性”——就像“红色”这样的常见描述性词在语义上对语言来说很重要一样。希望这能让您了解可能的方向。