本文整理汇总了Java中edu.smu.tspell.wordnet.WordNetDatabase类的典型用法代码示例。如果您正苦于以下问题:Java WordNetDatabase类的具体用法?Java WordNetDatabase怎么用?Java WordNetDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WordNetDatabase类属于edu.smu.tspell.wordnet包,在下文中一共展示了WordNetDatabase类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getSynsetsFromWord
import edu.smu.tspell.wordnet.WordNetDatabase; //导入依赖的package包/类
/**
* Extract from WordNet Database the synsets of a word
* @param wnDatabase WordNet Database
* @param word The word that we want to extract its synsets
* @param synsetType POS Tag of the word
* @return Array of Synsets
*/
public static Synset[] getSynsetsFromWord(WordNetDatabase wnDatabase, String word, SynsetType synsetType) {
Synset[] tmpSynsets;
if(synsetType == null)
tmpSynsets = wnDatabase.getSynsets(word);
else {
tmpSynsets = wnDatabase.getSynsets(word, synsetType);
// If the synset type is an adjective, check for adjective satellite too
if (synsetType == SynsetType.ADJECTIVE) {
tmpSynsets = (Synset[])ArrayUtils.addAll(tmpSynsets, wnDatabase.getSynsets(word, SynsetType.ADJECTIVE_SATELLITE));
}
}
return tmpSynsets;
}
开发者ID:butnaruandrei,项目名称:ShotgunWSD,代码行数:24,代码来源:WordUtils.java
示例2: extractSynsets
import edu.smu.tspell.wordnet.WordNetDatabase; //导入依赖的package包/类
/**
* Extract from WordNet Database only the synsets that contains the lemma of a word
* @param wnDatabase WordNet Database
* @param word The word that we want to extract its synsets
* @param synsetType POS Tag of the word
* @return Array of Synsets
*/
public static Synset[] extractSynsets(WordNetDatabase wnDatabase, String word, SynsetType synsetType) {
// Extract the senses for the word
Synset[] tmpSynsets = getSynsetsFromWord(wnDatabase, word, synsetType);
if(tmpSynsets.length == 0) {
tmpSynsets = getSynsetsFromWord(wnDatabase, new Sentence(word).lemma(0), synsetType);
}
ArrayList<Synset> synsets = new ArrayList<>();
// Keep only the senses that the lemma is match
for(Synset tmpSynset : tmpSynsets){
String[] senseKeys = tmpSynset.getSenseKeys();
for (int j = 0; j < senseKeys.length; j++) {
if(senseKeys[j].contains(word.replace(" ", "_"))){
synsets.add(tmpSynset);
break;
}
}
}
Synset[] resultSynsets;
if(synsets.isEmpty()) {
resultSynsets = tmpSynsets;
} else {
resultSynsets = new Synset[synsets.size()];
resultSynsets = synsets.toArray(resultSynsets);
}
return resultSynsets;
}
开发者ID:butnaruandrei,项目名称:ShotgunWSD,代码行数:40,代码来源:WordUtils.java
示例3: run
import edu.smu.tspell.wordnet.WordNetDatabase; //导入依赖的package包/类
/**
* Run the WSD Algorithm for the local window
*
* @param wnDatabase WordNet Database
*/
public void run(WordNetDatabase wnDatabase) {
buildWindowSynsetsArray(wnDatabase);
buildSynsetMapping();
Object[] synsetRepresentations = synsetRelatedness.computeSynsetRepresentations(windowWordsSynsets, windowWords, synset2WordIndex);
computeWordPairSynsetRelatedness(synsetRepresentations);
generateSynsetCombinations();
}
开发者ID:butnaruandrei,项目名称:ShotgunWSD,代码行数:14,代码来源:ShotgunWSDLocal.java
示例4: buildWindowSynsetsArray
import edu.smu.tspell.wordnet.WordNetDatabase; //导入依赖的package包/类
/**
* This method build and store an array that contains al synsets for all the words in the context window.
* This is usefully to keep a simple representation of a synset, and to access it fast, without the need to look in WordNet.
*
* @param wnDatabase WordNet Database
*/
protected void buildWindowSynsetsArray(WordNetDatabase wnDatabase) {
ArrayList<Synset> windowSynsets = new ArrayList<>();
Synset[] tmpSynsets;
int synsetStartIndex = 0, synsetLength;
// For each word in the context window.
for (int j = 0; j < windowWords.length; j++) {
// Extract the words synsets
tmpSynsets = WordUtils.extractSynsets(wnDatabase, windowWords[j], POSUtils.asSynsetType(windowWordsPOS[j]));
// Insert there synsets to an array
synsetLength = tmpSynsets.length;
if (tmpSynsets.length == 0) {
synsetLength += 1;
windowSynsets.add(null);
} else {
windowSynsets.addAll(Arrays.asList(tmpSynsets));
}
// Set the start index and the number of synsets
windowWordsSynsetStart[j] = synsetStartIndex;
windowWordsSynsetLength[j] = synsetLength;
// Increment the index position, for the new word
synsetStartIndex += synsetLength;
}
windowWordsSynsets = new Synset[windowSynsets.size()];
windowWordsSynsets = windowSynsets.toArray(windowWordsSynsets);
}
开发者ID:butnaruandrei,项目名称:ShotgunWSD,代码行数:38,代码来源:ShotgunWSDLocal.java
示例5: initWordNet
import edu.smu.tspell.wordnet.WordNetDatabase; //导入依赖的package包/类
public static boolean initWordNet(String wordNetDir) {
if (wordNetDir != null && !wordNetDir.matches("(?i)[\\p{Punct}\\s]*false[\\p{Punct}\\s]*")) {
if (new File(wordNetDir).isDirectory()) {
System.setProperty("wordnet.database.dir", wordNetDir);
wn_database = WordNetDatabase.getFileInstance();
return true;
} else {
System.err.println("The WordNet dictionary directory provided does not exist.");
System.err.println("Either disable the usage of WordNet or set its correct location in the config file.");
System.exit(1);
}
}
wn_database = null;
return false;
}
开发者ID:begab,项目名称:kpe,代码行数:16,代码来源:NGram.java
示例6: inWordNet
import edu.smu.tspell.wordnet.WordNetDatabase; //导入依赖的package包/类
public static boolean inWordNet(WordNetDatabase wnDatabase, String word, SynsetType synsetType) {
return wnDatabase.getSynsets(word, synsetType).length > 0;
}
开发者ID:butnaruandrei,项目名称:ShotgunWSD,代码行数:4,代码来源:WordUtils.java
示例7: loadWordNet
import edu.smu.tspell.wordnet.WordNetDatabase; //导入依赖的package包/类
public static void loadWordNet(String wnDirectory) {
System.setProperty("wordnet.database.dir", wnDirectory);
ShotgunWSDRunner.wnDatabase = WordNetDatabase.getFileInstance();
}
开发者ID:butnaruandrei,项目名称:ShotgunWSD,代码行数:5,代码来源:ShotgunWSDRunner.java
示例8: synWN
import edu.smu.tspell.wordnet.WordNetDatabase; //导入依赖的package包/类
public String synWN(String word, String tag, String wordnetPath) {
System.setProperty("wordnet.database.dir", wordnetPath);
// setting path for the WordNet Directory
// System.out.println("word: " + word);
WordNetDatabase database = WordNetDatabase.getFileInstance();
Synset[] synsets = null;
if (tag.contains("_V")) {
synsets = database.getSynsets(word, SynsetType.VERB);
} else if (tag.contains("_NN")) {
synsets = database.getSynsets(word, SynsetType.NOUN);
}
// Display the word forms and definitions for synsets retrieved
String synonym = "";
if (synsets.length > 0) {
ArrayList<String> al = new ArrayList<String>();
// add elements to al, including duplicates
HashSet<String> hs = new HashSet<String>();
for (int i = 0; i < synsets.length; i++) {
String[] wordForms = synsets[i].getWordForms();
// System.out.println(wordForms.length);
// synonym = wordForms[0].toString();
for (int j = 0; j < wordForms.length; j++) {
al.add(wordForms[j]);
}
}
// removing duplicates
hs.addAll(al);
al.clear();
al.addAll(hs);
// showing all synsets
// System.out.println("Quantity of synonyms " + al.size());
for (int j = 0; j < al.size(); j++) {
// System.out.println(al.get(j));
if (!al.get(j).equals(word)) {
synonym = al.get(j);
break;
}
}
if (synonym.equals("")) {
return word;
} else {
return synonym;
}
} else {
// System.err.println("No synsets exist that contain the word form
// '" + word + "'");
return word;
}
}
开发者ID:dice-group,项目名称:BENGAL,代码行数:53,代码来源:Paraphrasing.java
注:本文中的edu.smu.tspell.wordnet.WordNetDatabase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论