本文整理汇总了Java中edu.mit.jwi.item.ISynset.getWords方法的典型用法代码示例。如果您正苦于以下问题:Java ISynset.getWords方法的具体用法?Java ISynset.getWords怎么用?Java ISynset.getWords使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.mit.jwi.item.ISynset
的用法示例。
在下文中一共展示了ISynset.getWords方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMeanings
import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
private String getMeanings(int synset, POS pos){
String result = "";
ISynsetID synsetID = new SynsetID(synset, pos);
ISynset s = dict.getSynset(synsetID);
if(s == null) return "";
int i= 1;
for (IWord iword: s.getWords()){
result += i + " - ";
result += iword.getLemma() + "\n";
i++;
}
result += "Gloss: " + s.getGloss() + "\n\n";
return result;
}
示例2: getWords
import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
@Override
public List<String> getWords(int synset, String pos) {
ArrayList<String> words = new ArrayList<String>();
try {
dict.open();
} catch (IOException e) {
return words;
}
IWordID wordID1 = new WordID(synset,POS.valueOf(pos),1);
IWord word1 = dict.getWord(wordID1);
ISynset isynset = word1.getSynset() ;
for( IWord word : isynset.getWords () )
words.add(word.getLemma());
return words;
}
示例3: ExtractSynsetsSentence
import edu.mit.jwi.item.ISynset; //导入方法依赖的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.item.ISynset; //导入方法依赖的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: ExtractSynonymSentence
import edu.mit.jwi.item.ISynset; //导入方法依赖的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;
}
示例6: getSynonyms
import edu.mit.jwi.item.ISynset; //导入方法依赖的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;
}
示例7: getSynonyms
import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
/**
* Will return a list of synonyms for a word, given a set of permissible word classes
* @param word
* @param wordClass
* @return
*/
public static List<String> getSynonyms(String word, POS... wordClass){
List<String> synonyms = new ArrayList<String>();
synonyms.add(word.toLowerCase());
List<POS> acceptedWordClasses = Arrays.asList(wordClass);
try{
for(POS p : acceptedWordClasses){
IIndexWord iw = dict.getIndexWord(word, p);
if(iw != null){
for(IWordID wid : iw.getWordIDs()){
IWord wrd = dict.getWord(wid);
ISynset synset = wrd.getSynset();
for(IWord iwrd : synset.getWords()){
String lemma = iwrd.getLemma().toLowerCase();
if(!synonyms.contains(lemma))
synonyms.add(lemma);
}
}
}
}
}catch(IllegalArgumentException iae){
System.out.println("Illegal argument: synonym "+word);
}
Collections.sort(synonyms);
return synonyms;
}
示例8: parseSynset
import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
String parseSynset(ISynset synset){
String ret = "";
if(synset.getWords().size()==1)return ret;
ret+="<p>Synsets:   ";
for(IWord word:synset.getWords()){
String t=word.getLemma();
if(!t.equals(wordName)){
ret += "<a href="+t+">"+t.replaceAll("_", " ")+"</a>   ";
}
}
return ret;
}
示例9: getWordsOfSynsets
import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
/**
* @param iSynsets
* @return
*/
private Set<String> getWordsOfSynsets(ISynset[] iSynsets) {
Set<String> words = new HashSet<String>();
for (ISynset synset : iSynsets)
for (IWord iWord : synset.getWords())
words.add(iWord.getLemma());
return words;
}
示例10: getSynonyms
import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
public Map<MappedString, Float> getSynonyms(IWord word, int depth, int maxDepth, List<TraceElement> trace) {
Map<MappedString, Float> res = new HashMap<MappedString, Float>();
if (depth > maxDepth) {
return res;
}
List<IWordID> words;
synchronized (dict) {
words = dict.getIndexWord(word.getLemma(), word.getPOS()).getWordIDs();
}
for (IWordID sameWordInOtherSynset : words) {
ISynset s;
synchronized (dict) {
s = dict.getWord(sameWordInOtherSynset).getSynset();
}
for (IWord synonym : s.getWords()) {
float score = 1.0f - (float)depth / (maxDepth + 1);
List<TraceElement> _trace = new LinkedList<TraceElement>(trace);
// we don't have to mention that a word is a synonym of itself
if (!word.getLemma().equals(synonym.getLemma())) {
_trace.add(new TraceElement(synonym.getLemma() + " (synonym)", getWordNetUrl(synonym)));
}
addSynonym(res, synonym.getLemma(), _trace, score);
addSynonyms(res, getSynonyms(synonym, depth + 1, maxDepth, _trace));
}
}
return res;
}
示例11: getRelatedWords
import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
public Map<MappedString, Float> getRelatedWords(ISynset s, int depth, int maxDepth, IPointer relationType, boolean assignDepthPenalty, List<TraceElement> trace) {
if (depth == maxDepth) {
return Collections.emptyMap();
}
float scoreInThisDepth = 1.0f;
if (assignDepthPenalty) {
scoreInThisDepth -= (float)depth / maxDepth;
}
Map<MappedString, Float> res = new HashMap<MappedString, Float>();
// Map foo = word.getRelatedMap();
List<ISynsetID> sIDs = s.getRelatedSynsets(relationType);
for (ISynsetID sID : sIDs) {
ISynset hS;
synchronized (dict) {
hS = dict.getSynset(sID);
}
List<TraceElement> _trace = new LinkedList<TraceElement>(trace);
_trace.add(new TraceElement(hS.getGloss() + " (" + relationType.getName() + ")", ""));
for (IWord h : hS.getWords()) {
List<TraceElement> __trace = new LinkedList<TraceElement>(trace);
__trace.add(new TraceElement(h.getLemma() + " (" + relationType.getName() + ")", getWordNetUrl(h)));
addSynonym(res, h.getLemma(), __trace, scoreInThisDepth);
}
addSynonyms(res, getRelatedWords(hS, depth + 1, maxDepth, relationType, assignDepthPenalty, _trace));
}
return res;
}
示例12: ExtractSynonymFile
import edu.mit.jwi.item.ISynset; //导入方法依赖的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;
}
示例13: getSynonyms
import edu.mit.jwi.item.ISynset; //导入方法依赖的package包/类
/**
* 根据一定规则来获取当前词的最佳同义词
* 2015-6-9 19:47:30 添加synchronized关键字,jwi不是线程安全的
* @param dict
* @param word
* @param selectedSynonymsWords 文章中已经选择的同义词集合
* @return
*/
public synchronized static List<Word> getSynonyms(IDictionary dict, Word word){
List<Word> synonymsWords = new ArrayList<Word>();
IIndexWord idxWord = null;
if(POS_NOUN.contains(word.getPos())){
idxWord = dict.getIndexWord(word.getLemma(), POS.NOUN);
}else if(POS_VERB.contains(word.getPos())){
idxWord = dict.getIndexWord(word.getLemma(), POS.VERB);
}else if(POS_ADVERB.contains(word.getPos())){
idxWord = dict.getIndexWord(word.getLemma(), POS.ADVERB);
}else if(POS_ADJ.contains(word.getPos())){
idxWord = dict.getIndexWord(word.getLemma(), POS.ADJECTIVE);
}
if(idxWord == null) {
return synonymsWords;
}
IWordID wordID = idxWord.getWordIDs().get(0); // 1st meaning
IWord iword = dict.getWord(wordID);
ISynset synset = iword.getSynset (); //ISynset是一个词的同义词集的接口
for(IWord w : synset.getWords()){
Word synonymsWord = null;
try {
synonymsWord = (Word) word.clone();
synonymsWord.setName(w.getLemma());
synonymsWord.setLemma(w.getLemma());
} catch (CloneNotSupportedException e) {
log.error("Clone word[" + word + "] error!", e);
}
if(null != synonymsWord) {
synonymsWords.add(synonymsWord);
}
}
return synonymsWords;
}