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<BabelSense> 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<BabelSense> senses = by.getSenses();
// Collects all BabelGlosses in the given source for this BabelSynset.
List<BabelGloss> glosses = by.getGlosses();
// Collects all BabelExamples for this BabelSynset.
List<BabelExample> examples = by.getExamples();
// Gets the images (BabelImages) of this BabelSynset.
List<BabelImage> images = by.getImages();
// Collects all the edges incident on this BabelSynset.
List<BabelSynsetRelation> edges = by.getOutgoingEdges();
// Gets the BabelCategory objects of this BabelSynset.
List<BabelCategory> 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: <a href="https://upload.wikimedia.org/wikipedia/commons/d/d6/Location_Vietnam_ASEAN.svg">Location_Vietnam_ASEAN.svg#OMWIKI</a>
Image: <a href="https://upload.wikimedia.org/wikipedia/commons/8/80/Asia_%28orthographic_projection%29.svg">Asia_(orthographic_projection).svg#OMWIKI</a>
...
Image: <a href="https://upload.wikimedia.org/wikipedia/commons/5/5f/Flag_of_Quebec.svg">Flag_of_Quebec.svg#WIKIDATA</a>
Image: <a href="https://upload.wikimedia.org/wikipedia/commons/4/4b/Flag_of_Libya_%281977-2011%29.svg">Flag_of_Libya_(1977-2011).svg#WIKIDATA</a>
Image: <a href="https://upload.wikimedia.org/wikipedia/commons/3/34/Red_star.svg">Red_star.svg#WIKIDATA</a>
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();