通过BabelNet_Java_API获取BabelNet数据

2018-05-10

主要的类包括

  • BabelNet
  • BabelSynset
  • BabelSense

BabelNet类是访问BabelNet数据的入口,要想获取数据,首先就要建立BabelNet实例

BabelNet bn = BabelNet.getInstance();

已经通过网站得知我需要查询的对象的SynsetID为“bn:00004315n”
获取Synset对象
BabelSynset by = bn.getSynset(new BabelSynsetID("bn:00004315n"));
检索BabelSynset中包含的信息:

// Most relevant BabelSense to this BabelSynset for a given language.
Optional bs = by.getMainSense(Language.EN);

// Gets the part of speech of this BabelSynset.
POS pos = by.getPOS();

// True if the BabelSynset is a key concept
boolean iskeyConcept = by.isKeyConcept();
       
// Gets the senses contained in this BabelSynset.
List senses = by.getSenses();

// Collects all BabelGlosses in the given source for this BabelSynset.
List glosses = by.getGlosses();

// Collects all BabelExamples for this BabelSynset.
List examples = by.getExamples();

// Gets the images (BabelImages) of this BabelSynset.
List images = by.getImages();

// Collects all the edges incident on this BabelSynset.
List edges = by.getOutgoingEdges();

// Gets the BabelCategory objects of this BabelSynset.
List cats = by.getCategories();

通过PrintWriter将结果保存到文件

PrintWriter out = new PrintWriter("Result.txt");
out.println(...);
out.close();

得到类似下面的结果:

MainSense: WN:EN:Vietnam
POS:NOUN
iskeyConcept: false
Sense: WN:EN:Vietnam
Sense: WN:EN:Socialist_Republic_of_Vietnam
...
Sense: WIKIRED:EN:Red_Vietnam_(modern)
glosses: A communist state in Indochina on the South China Sea; achieved independence from France in 1945
glosses: Vietnam, officially the Socialist Republic of Vietnam, is the easternmost country on the Indochina Peninsula in Southeast Asia.
...
glosses: Country in Southeast Asia.
glosses: Vietnam is a country in East Asia.
Image: Location_Vietnam_ASEAN.svg#OMWIKI
Image: Asia_(orthographic_projection).svg#OMWIKI
...
Image: Flag_of_Quebec.svg#WIKIDATA
Image: Flag_of_Libya_(1977-2011).svg#WIKIDATA
Image: Red_star.svg#WIKIDATA
Category: BNCAT:EN:1976_establishments_in_Vietnam
Category: BNCAT:EN:Communist_states
...
Category: BNCAT:EN:Vietnam
Category: BNCAT:EN:Vietnamese-speaking_countries_and_territories

这里的问题是当给getSense()方法传递语言参数“language.ZH”后,返回的结果为空!可是网站明明是有中文表示的阿~~~

对于getOutgoingEdges()的到的关系,可以获取 “关系名”,“目标节点”

relation.getPointer().getName();
relation.getTarget();

你可能感兴趣的:(通过BabelNet_Java_API获取BabelNet数据)