当前位置: 首页>>代码示例>>Java>>正文


Java IDictionary.open方法代码示例

本文整理汇总了Java中edu.mit.jwi.IDictionary.open方法的典型用法代码示例。如果您正苦于以下问题:Java IDictionary.open方法的具体用法?Java IDictionary.open怎么用?Java IDictionary.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.mit.jwi.IDictionary的用法示例。


在下文中一共展示了IDictionary.open方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
}
 
开发者ID:utk4rsh,项目名称:question-classifier,代码行数:24,代码来源:HeadWordExtractor.java

示例2: 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();
	}
 
开发者ID:kariminf,项目名称:langpi,代码行数:22,代码来源:WordNetTest.java

示例3: 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;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:33,代码来源:Synonyms.java

示例4: 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;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:33,代码来源:WordNetFile.java

示例5: 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;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:39,代码来源:WordNetFile.java

示例6: 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;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:37,代码来源:WordNetFile.java

示例7: 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;
}
 
开发者ID:annefried,项目名称:sitent,代码行数:12,代码来源:WordNetUtils.java

示例8: openDictionary

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
/**
 * 打开词典
 * @param dictPath
 * @return
 * @throws IOException
 */
public static IDictionary openDictionary(String dictPath) throws IOException{
    if(dicts.get(dictPath) == null){
        synchronized (WordNetUtil.class) {
            if(dicts.get(dictPath) == null){
                URL url=new URL("file", null, dictPath);
                IDictionary dict = new Dictionary(url);
                dict.open();//打开词典
                dicts.put(dictPath, dict);
            }
        }
    }
    return dicts.get(dictPath);
}
 
开发者ID:procyon-lotor,项目名称:event-direct-mts,代码行数:20,代码来源:WordNetUtil.java

示例9: main

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public static void main(String[] args) {
    IDictionary wordnet= new Dictionary(new File("resources/dict/"));
    try {
        wordnet.open();
    } catch (IOException ex) {
        Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex);
    }
    HashMap<String,List<Wiki2WordnetMapping>> babel=Mapper.loadBabelnetMappings("resources/babelnetMappings.txt.bz2");
    HashMap<String,Wiki2WordnetMapping> fernan=Mapper.loadFernandoMappings("resources/fernandoMappings.txt.bz2");        
    List<String> wikiTitles = new ArrayList<>(Arrays.asList("Saturn","Moon","Cosmologist"));
    List<String> desambiguationContext= Arrays.asList("Mars", "Solar System");
    HashMap<String,Integer> maps=Mapper.babelnetFernandoToWordnet(babel,fernan , wikiTitles, "/tmp/ukb", wordnet,desambiguationContext,"/home/ukb/ukbdir/bin");
    System.out.println(maps);
}
 
开发者ID:Neuw84,项目名称:Wikipedia2WordNet,代码行数:15,代码来源:Example.java

示例10: main

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {


        // construct the dictionary object and open it
        URL u = ClassLoader.getSystemResource("resources/wordnet/dict");
        IDictionary dict = new Dictionary(u);
        dict.open();
        
        // look up first sense of the word "dog"
        IIndexWord idxWord = dict.getIndexWord("computer", POS.NOUN);
        IWordID wordID = idxWord.getWordIDs().get(0);
        IWord word = dict.getWord(wordID);
        System.out.println(word.toString());
        System.out.println("Id = " + wordID);
        System.out.println("Lemma = " + word.getLemma());
        System.out.println("Synset words = " + word.getSynset().getWords());
        System.out.println("Related Synsets = " + word.getSynset().getRelatedSynsets());
        System.out.println("Gloss = " + word.getSynset().getGloss());
        System.out.println("Verbframes = " + word.getVerbFrames());
        System.out.println("POS = " + word.getPOS());
        System.out.println("Related words = " + word.getRelatedMap());
        List<String> relatedWords = word.getRelatedWords().stream().map(
                    (IWordID t) -> (String)dict.getWord(t).getLemma() ).collect(Collectors.toList());
        System.out.println("Related words = " + relatedWords);
        System.out.println("Sensekey = " + word.getSenseKey());
        System.out.println("AdjMarker = " + word.getAdjectiveMarker());

    }
 
开发者ID:automenta,项目名称:netentionj-desktop,代码行数:29,代码来源:WordnetDemo.java

示例11: ExtractSynonymFile

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public List<ExtractSynonym> ExtractSynonymFile(File filePath) throws MalformedURLException, IOException
{
    List<ExtractSynonym> lstSynset=new ArrayList<>();
    BufferedReader reader=new BufferedReader(new FileReader(filePath));
    String Line="";
    List<String> lstText=new ArrayList<>();
    while((Line=reader.readLine())!=null)
    {
        lstText.add(Line);
    }
    for(String Sentence:lstText)
    {
        for(String str:Sentence.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()+",";

                 }
                lstSynset.add(new ExtractSynonym(str, strSynset));
             }
             catch(Exception ex)
             {
             }
         }
        }
    }
    return lstSynset;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:44,代码来源:WordNetFile.java

示例12: testTopic

import edu.mit.jwi.IDictionary; //导入方法依赖的package包/类
public static void  testTopic() 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();
	// look up first sense of the word " dog "
	WordnetStemmer ws = new WordnetStemmer(dict);
	
	
	//dog: 10114209
	//car: 2958343
	//home: 8559508
	//midnight
	IWordID wordID1 = new WordID(15168185,POS.NOUN,1);
	IWord word1 = dict.getWord(wordID1);
	
	System.out.println("LexFile = " + word1.getSynset().getLexicalFile());
	
	System.out.println("Lemma = " + word1.getLemma());
	
	System.out.println("Gloss = " + word1.getSynset().getGloss()) ;
	
	System.out.print("Synonyms: ");
	for(IWord iword : word1.getSynset().getWords())
		System.out.print(iword.getLemma() + ", ");
	System.out.println("\n-----------------------") ;
	System.out.println("related: ") ;
	
	Map<IPointer, List<ISynsetID>> k = word1.getSynset().getRelatedMap();
	for(IPointer ip : k.keySet()){
		System.out.print(ip.getName() + ": ");
		for (ISynsetID isid : k.get(ip)){
			System.out.print(isid.getOffset() + ".");
			ISynset ss = dict.getSynset(isid);
			System.out.print(ss.getPOS() + "=");
			IWord iw = dict.getWord(new WordID(ss.getOffset(),ss.getPOS(), 1));
			System.out.print(iw.getLemma() + ", ");
		}
			
		System.out.println();
	}
	
	
	/*
	for(IWordID wordID: idxWord.getWordIDs()){
		IWord word = dict.getWord(wordID);
		
		//System.out.println("Sence = " + word.getSenseKey().getLexicalID()) ;
		System.out.println("Lemma = " + word.getLemma()) ;
		System.out.println("Gloss = " + word.getSynset().getGloss()) ;
		
		System.out.println("Synonyms: ");
		
		for(IWord iword : word.getSynset().getWords())
			System.out.print(iword.getLemma() + ", ");
		System.out.println("\n-----------------------");
		
	}
	*/
	
	dict.close();
	
}
 
开发者ID:kariminf,项目名称:langpi,代码行数:65,代码来源:WordNetTest.java


注:本文中的edu.mit.jwi.IDictionary.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。