2016-11-06 97 views
-1

這是使用SimpleNLG Java API完成的將複數名詞轉換爲單數

我想將「精靈」轉換爲精靈。下面的代碼從單數轉換爲複數,如何修改將其從複數轉換爲單數?

final XMLLexicon xmlLexicon = new XMLLexicon(); 
final WordElement word = xmlLexicon.getWord("elves", LexicalCategory.NOUN); 
final InflectedWordElement pluralWord = new InflectedWordElement(word); 
pluralWord.setPlural(true); 
final Realiser realiser = new Realiser(xmlLexicon); 
System.out.println(realiser.realise(pluralWord)); 
+0

也許試試pluralWord.setPlural(false);而不是pluralWord.setPlural(true); ...你是什麼意思的「做相反的事情」?它並不需要單數,是嗎? – Wolf

+0

我不認爲你可以:http://stackoverflow.com/questions/1377020/can-you-programmatically-detect-pluralizations-of-english-words-and-derive-the –

+0

@RC .:你爲什麼也這樣覺得?當然,你可以通過字典把複數變成單數,反之亦然......你的鏈接不會另有說明... – Wolf

回答

1

所以顯然是這個API中沒有setSingular()方法(我真的指望那一個,我認爲這是一種有趣的,沒有一個這樣的事情。)也沒有setPlural()方法要麼截至V4。

[1]請注意,在SimpleNLG V4中,沒有任何詞典方法可以直接獲取詞的變形變體;換句話說,在SimpleNLG V3的getPlural(),getPastParticiple(), 等方法的V4中不存在相當於 。在V4中有可能計算字體變形的變體 ,但是這個過程比較複雜:基本上我們需要在基本形式周圍創建一個InflectedWordElement,爲這個InflectedWordElement添加適當的 特徵,然後實現它。

我認爲這可能做的伎倆:(我沒有測試它,因爲我沒有時間,現在)

final XMLLexicon xmlLexicon = new XMLLexicon(); 
final WordElement word = xmlLexicon.getWord("elves", LexicalCategory.NOUN); 
final InflectedWordElement singularWord = new InflectedWordElement(word); 
WordElement sw = singularWord.getBaseWord(); 
final Realiser realiser = new Realiser(xmlLexicon); 
System.out.println(realiser.realise(sw)); 

如果不工作,你或其他任何人,歡迎看here(docs)here(tutorial)作爲答案。

+0

它沒有工作,但讓我更靠近一步。謝謝。 –

+0

@JeremyHunts你做到了嗎? –