本文整理汇总了Java中edu.mit.jwi.IDictionary类的典型用法代码示例。如果您正苦于以下问题:Java IDictionary类的具体用法?Java IDictionary怎么用?Java IDictionary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IDictionary类属于edu.mit.jwi包,在下文中一共展示了IDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerSynonyms
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
private void registerSynonyms() {
EventBus eventBus = vertx.eventBus();
eventBus.consumer(WordnetAddresses.SYNONYMS.getAddress(), (Handler<Message<String>>) message -> {
String body = message.body();
IDictionary dictionary = dictionaryCache.getDictionary();
IIndexWord idxWord = dictionary.getIndexWord(body, POS.NOUN);
IWordID wordID = idxWord.getWordIDs().get(0); // 1st meaning
IWord word = dictionary.getWord(wordID);
ISynset synset = word.getSynset();
List<String> synonyms = synset.getWords().stream().map(IWord::getLemma).collect(Collectors.toList());
message.reply(new JsonArray(synonyms));
});
}
示例2: extractLastHypernym
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
private String extractLastHypernym(Token token) throws IOException {
String result = token.getCoveredText();
String path = "wordnet" + File.separator + "dict";
URL url = new URL("file", null, path);
IDictionary dict = new Dictionary(url);
dict.open();
IIndexWord idxWord = dict.getIndexWord(token.getCoveredText().toLowerCase(), getCorrectPOS(token.getPos()));
if (idxWord != null && idxWord.getWordIDs().size() > 0) {
IWordID wordID = idxWord.getWordIDs().get(0);
IWord word = dict.getWord(wordID);
ISynset synset = word.getSynset();
List<ISynsetID> hypernyms = synset.getRelatedSynsets(Pointer.HYPERNYM);
List<IWord> words;
for (ISynsetID sid : hypernyms) {
words = dict.getSynset(sid).getWords();
for (Iterator<IWord> i = words.iterator(); i.hasNext();) {
result = i.next().getLemma();
}
}
}
dict.close();
return result;
}
示例3: isHypernym
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
/**
* written by anne
*
* @param dict
* @param word
* @param posTag
* @param firstSenseOnly
* @return
*/
public static Boolean isHypernym(IDictionary dict, ISynset synset, ISynset hypernym, boolean firstSenseOnly) {
if (synset.equals(hypernym)) {
return true;
}
for (ISynsetID iSynsetId : synset.getRelatedSynsets(Pointer.HYPERNYM)) {
ISynset hyperSynset = dict.getSynset(iSynsetId);
if (isHypernym(dict, hyperSynset, hypernym, firstSenseOnly)) {
return true;
}
}
return false;
}
示例4: testWordSearch
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
public static void testWordSearch() throws IOException{
// construct the URL to the Wordnet dictionary directory
File file =new File("wordnetDB/dict/");
// construct the dictionary object and open it
IDictionary dict = new Dictionary(file) ;
dict.open();
IIndexWord idxWord = dict.getIndexWord ("midnight" , POS.NOUN) ;
if(idxWord == null) System.out.println("no word\n--------\n");
for (IWordID iword: idxWord.getWordIDs()){
System.out.println("offset: " + iword.getSynsetID().getOffset());
IWord word = dict.getWord(iword);
System.out.println("gloss: " + word.getSynset().getGloss());
}
//System.out.println("offset: " + idxWord.getWordIDs().get(0).getSynsetID().getOffset());
dict.close();
}
示例5: ExtractSynsetsSentence
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
public List<SynonymDomain> ExtractSynsetsSentence(String Sentence,File englishStopwordsFilePath) throws IOException, Exception
{
List<SynonymDomain> lstSynset=new ArrayList<>();
String sentenceKeyWords=EX.ExtractKeyword(Sentence, englishStopwordsFilePath);
for(String str:sentenceKeyWords.split(","))
{
String strSynset="";
File dicFile=new File(path);
IDictionary dict=new Dictionary(dicFile);
dict.open();
WordnetStemmer stemmer=new WordnetStemmer(dict);
try
{
List<String> lstStem=stemmer.findStems(str, POS.NOUN);
IIndexWord idxWord = dict . getIndexWord (lstStem.get(0), POS.NOUN);
IWordID wordID = idxWord . getWordIDs ().get(0);
IWord word = dict.getWord(wordID);
ISynset sen=word.getSynset();
for(IWord w:sen.getWords())
{
strSynset+=w.getLemma()+",";
}
lstSynset.add(new SynonymDomain(str, strSynset));
}
catch(Exception ex)
{
}
}
return lstSynset;
}
示例6: ExtractSynonymWord
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
@Override
public List<String> ExtractSynonymWord(String word) throws URISyntaxException, IOException
{
List<String> lstSynonym=new ArrayList<>();
java.net.URL url = getClass().getClassLoader().getResource("dict\\");
//File dicFile = new File(url.toURI());
String strSynset="";
IDictionary dict=new Dictionary(new File(path));
dict.open();
WordnetStemmer stemmer=new WordnetStemmer(dict);
try
{
List<String> lstStem=stemmer.findStems(word, POS.NOUN);
for(int i=0;i<1000;i++)
{
IIndexWord idxWord = dict . getIndexWord (lstStem.get(0), POS.NOUN);
IWordID wordID = idxWord . getWordIDs ().get(i);
IWord words = dict.getWord(wordID);
ISynset sen=words.getSynset();
for(IWord w:sen.getWords())
{
lstSynonym.add(w.getLemma());
}
}
}
catch(Exception ex)
{
}
return lstSynonym;
}
示例7: ExtractHypernymWord
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
@Override
public List<String> ExtractHypernymWord(String word) {
//String strHypernym="";
List<String> lstHypernym=new ArrayList<>();
try
{
// java.net.URL url = getClass().getClassLoader().getResource("dict\\");
// File dicFile = new File(url.toURI());
IDictionary dict=new Dictionary(new File(path));
dict.open();
WordnetStemmer stemmer=new WordnetStemmer(dict);
List<String> lstStem=stemmer.findStems(word, POS.NOUN);
for(int j=0;j<1000;j++)
{
IIndexWord idxWord = dict.getIndexWord(lstStem.get(0),POS.NOUN);
IWordID wordID = idxWord.getWordIDs().get (j) ;
IWord mywords = dict . getWord (wordID);
ISynset sen=mywords.getSynset();
List <ISynsetID> hypernyms = sen.getRelatedSynsets (Pointer.HYPERNYM);
List<IWord> words;
for(ISynsetID sid : hypernyms)
{
words = dict . getSynset (sid). getWords ();
for( Iterator <IWord > i = words . iterator (); i. hasNext () ;)
{
lstHypernym.add((i. next (). getLemma ()));
//if(i. hasNext ())
// strHypernym+=",";
}
}
}
}
catch(Exception ex)
{
}
return lstHypernym;
}
示例8: ExtractSynonymSentence
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
public List<ExtractSynonym> ExtractSynonymSentence(String inputSentence) throws MalformedURLException, IOException
{
List<ExtractSynonym> lstSynset=new ArrayList<>();
for(String str:inputSentence.split(" "))
{
String strSynset="";
File dicFile=new File(path);
IDictionary dict=new Dictionary(dicFile);
dict.open();
WordnetStemmer stemmer=new WordnetStemmer(dict);
for(int j=0;j<10;j++)
{
try
{
List<String> lstStem=stemmer.findStems(str, POS.NOUN);
IIndexWord idxWord = dict . getIndexWord (lstStem.get(0), POS.NOUN);
IWordID wordID = idxWord . getWordIDs ().get(j);
IWord word = dict.getWord(wordID);
ISynset sen=word.getSynset();
for(IWord w:sen.getWords())
{
strSynset+=w.getLemma()+",";
}
}
catch(Exception ex)
{
}
}
lstSynset.add(new ExtractSynonym(str, strSynset));
}
return lstSynset;
}
示例9: getDictionary
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
/**
* Initialize WordNet dictionary.
*/
public static IDictionary getDictionary(String wordNetPath) throws IOException {
URL url = new URL("file", null, wordNetPath);
IDictionary iDictionary = new Dictionary(url);
iDictionary.open();
return iDictionary;
}
示例10: getStems
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
/**
* Get a list of possible stems. Assume we are looking up a noun.
*/
public static List<String> getStems(String word, String posTag, IDictionary iDictionary) {
POS pos = POS.getPartOfSpeech(posTag.charAt(0));
if (pos == null) {
return new ArrayList<String>();
}
WordnetStemmer wordnetStemmer = new WordnetStemmer(iDictionary);
List<String> stems = wordnetStemmer.findStems(word, pos);
return stems;
}
示例11: getSynsets
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
/**
* Retrieve a set of synonyms for a word. Use only the first sense if
* useFirstSense flag is true.
*/
public static List<ISynset> getSynsets(IDictionary iDictionary, String word, String posTag,
boolean firstSenseOnly) {
// need a set to avoid repeating words
List<ISynset> synonyms = new LinkedList<ISynset>();
POS pos = POS.getPartOfSpeech(posTag.charAt(0));
if (pos == null) {
return synonyms;
}
IIndexWord iIndexWord = iDictionary.getIndexWord(word, pos);
if (iIndexWord == null) {
return synonyms; // no senses found
}
// iterate over senses
for (IWordID iWordId : iIndexWord.getWordIDs()) {
IWord iWord = iDictionary.getWord(iWordId);
ISynset iSynset = iWord.getSynset();
synonyms.add(iSynset);
if (firstSenseOnly) {
break;
}
}
return synonyms;
}
示例12: getSynonyms
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
/**
* Retrieve a set of synonyms for a word. Use only the first sense if
* useFirstSense flag is true.
*/
public static HashSet<String> getSynonyms(IDictionary iDictionary, String word, String posTag,
boolean firstSenseOnly) {
// need a set to avoid repeating words
HashSet<String> synonyms = new HashSet<String>();
POS pos = POS.getPartOfSpeech(posTag.charAt(0));
if (pos == null) {
return synonyms;
}
IIndexWord iIndexWord = iDictionary.getIndexWord(word, pos);
if (iIndexWord == null) {
return synonyms; // no senses found
}
// iterate over senses
for (IWordID iWordId : iIndexWord.getWordIDs()) {
IWord iWord = iDictionary.getWord(iWordId);
ISynset iSynset = iWord.getSynset();
for (IWord synsetMember : iSynset.getWords()) {
synonyms.add(synsetMember.getLemma());
}
if (firstSenseOnly) {
break;
}
}
return synonyms;
}
示例13: getHypernyms
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
/**
* Retrieve a set of hypernyms for a word. Use only the first sense if
* useFirstSense flag is true.
*/
public static HashSet<String> getHypernyms(IDictionary dict, String word, String posTag, boolean firstSenseOnly) {
HashSet<String> hypernyms = new HashSet<String>();
POS pos = POS.getPartOfSpeech(posTag.charAt(0));
if (pos == null) {
return hypernyms;
}
IIndexWord iIndexWord = dict.getIndexWord(word, pos);
if (iIndexWord == null) {
return hypernyms; // no senses found
}
// iterate over senses
for (IWordID iWordId : iIndexWord.getWordIDs()) {
IWord iWord1 = dict.getWord(iWordId);
ISynset iSynset = iWord1.getSynset();
// multiple hypernym chains are possible for a synset
for (ISynsetID iSynsetId : iSynset.getRelatedSynsets(Pointer.HYPERNYM)) {
List<IWord> iWords = dict.getSynset(iSynsetId).getWords();
for (IWord iWord2 : iWords) {
String lemma = iWord2.getLemma();
hypernyms.add(lemma.replace(' ', '_')); // also get rid of
// spaces
}
}
if (firstSenseOnly) {
break;
}
}
return hypernyms;
}
示例14: getHyperHypernyms
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
public static HashSet<String> getHyperHypernyms(IDictionary dict, String word, String posTag,
boolean firstSenseOnly) {
HashSet<String> hypernyms = new HashSet<String>();
POS pos = POS.getPartOfSpeech(posTag.charAt(0));
if (pos == null) {
return hypernyms;
}
IIndexWord iIndexWord = dict.getIndexWord(word, pos);
if (iIndexWord == null) {
return hypernyms; // no senses found
}
// iterate over senses
for (IWordID iWordId : iIndexWord.getWordIDs()) {
IWord iWord1 = dict.getWord(iWordId);
ISynset iSynset = iWord1.getSynset();
for (ISynsetID iSynsetId1 : iSynset.getRelatedSynsets(Pointer.HYPERNYM)) {
for (ISynsetID iSynsetId2 : dict.getSynset(iSynsetId1).getRelatedSynsets(Pointer.HYPERNYM)) {
List<IWord> iWords = dict.getSynset(iSynsetId2).getWords();
for (IWord iWord2 : iWords) {
String lemma = iWord2.getLemma();
hypernyms.add(lemma.replace(' ', '_')); // also get rid
// of spaces
}
}
}
if (firstSenseOnly) {
break;
}
}
return hypernyms;
}
示例15: main
import edu.mit.jwi.IDictionary; //导入依赖的package包/类
/**
* test
*
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
IDictionary dict = WordNetUtils.getDictionary("resources/wordnet3.0");
ISynset hypernym = getSynsets(dict, "act", "VERB", false).get(0);
System.out.println(hypernym.getGloss());
boolean b = isHypernym(dict, "exist", "VERB", hypernym, false);
System.out.println(b);
System.out.println(isHypernym(dict, "exist", "VERB", "buy", false));
// getRoots(dict);
// System.out.println(getRoots(dict).size());
ISynset mother = getSynsets(dict, "mother", "N", false).get(0);
System.out.println(mother);
ISynset person = getSynsets(dict, "person", "N", false).get(0);
System.out.println(person);
System.out.println(isHypernym(dict, mother, person, false));
System.out.println(getRoots(dict, "N").size());
for (ISynset s : getRoots(dict, "N")) {
System.out.println("Noun root: " + s);
}
}