本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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();
}