如何将知识 statements/relationships 从文本文件映射到(有向)图

How to map knowledge statements/relationships from text file to (directed) graph

我在 .txt 文件中有以下数据,我需要将其映射到图表,但我真的不知道该怎么做?我的意思是格式化。我不允许更改文件中的数据,但我需要映射 vertices/edges 但我不知道如何获取字符串的一部分(从文本文件中的一行)然后映射边缘到该字符串的末尾?有道理吗?

这是有问题的文本文件

任何帮助都会很棒。谢谢!

Trout is-a fish
Fish has gills
Fish has fins
Fish is food
Fish is-an animal
Apple is-a fruit
Fruit has stem
Fruit is food
Fruit is-a vegetable
Animal is-a living-thing
Vegetable is-a living-thing
Cod is-a fish
Trout lives-in freshwater
Cod lives-in saltwater
Tiger is-a cat
Tiger has stripes
Tiger is wild
Tabbie is-a cat
Tabbie has stripes
Tabbie is-a pet
Flag has stripes
Flag is-an artifact
Cat is-a mammal
Mammal is-an animal
Dog is-a mammal

对于每一行,拆分 space。

String[] lineParts = line.split(" ");

例如,您将拥有 lineParts[1] 中的关系类型。然后您可以使用第 0 部分和第 2 部分在您选择的数据结构中构建图形。