2018-05-10
主要的類包括
- BabelNet
- BabelSynset
- BabelSense
BabelNet類是訪問BabelNet數(shù)據(jù)的入口,要想獲取數(shù)據(jù)矩乐,首先就要建立BabelNet實例
BabelNet bn = BabelNet.getInstance();
已經(jīng)通過網(wǎng)站得知我需要查詢的對象的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將結(jié)果保存到文件
PrintWriter out = new PrintWriter("Result.txt");
out.println(...);
out.close();
得到類似下面的結(jié)果:
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 >Location_Vietnam_ASEAN.svg#OMWIKI</a>
Image: <a >Asia_(orthographic_projection).svg#OMWIKI</a>
...
Image: <a >Flag_of_Quebec.svg#WIKIDATA</a>
Image: <a >Flag_of_Libya_(1977-2011).svg#WIKIDATA</a>
Image: <a >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()方法傳遞語言參數(shù)“l(fā)anguage.ZH”后宴倍,返回的結(jié)果為空身腻!可是網(wǎng)站明明是有中文表示的阿~~~
對于getOutgoingEdges()的到的關系诗越,可以獲取 “關系名”驱犹,“目標節(jié)點”
relation.getPointer().getName();
relation.getTarget();