本文整理汇总了Java中edu.mit.jwi.item.ISynset类的典型用法代码示例。如果您正苦于以下问题:Java ISynset类的具体用法?Java ISynset怎么用?Java ISynset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ISynset类属于edu.mit.jwi.item包,在下文中一共展示了ISynset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractLastHypernym
import edu.mit.jwi.item.ISynset; //导入依赖的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: findDepth
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
private int findDepth(ISynset synset) {
if (synset.getRelatedSynsets(Pointer.HYPERNYM).isEmpty()) { return 0; }
List<Set<ISynset>> list = new ArrayList<>();
Set<ISynset> set = new HashSet<>();
set.add(synset);
list.add(set);
boolean topReached = false;
int depth = -1;
while (!topReached) {
Set<ISynset> nextSet = new HashSet<>();
for (ISynset syn : list.get(list.size()-1)) {
List<ISynsetID> hyperIDs = syn.getRelatedSynsets(Pointer.HYPERNYM);
if (!hyperIDs.isEmpty()) {
for (ISynsetID hyperID : hyperIDs) { nextSet.add(dict.getSynset(hyperID)); }
} else {
topReached = true;
depth = list.size()-1;
break;
}
}
list.add(nextSet);
}
return depth;
}
示例3: isHypernym
import edu.mit.jwi.item.ISynset; //导入依赖的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: getT
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
public String getT(){
if(wordName==null)return "";
String ret = "<html><body>";
ret+= "<center><h1><b>"+wordName.replaceAll("_", " ")+"</b></h1></center>";
for(int i=0;i<4;++i){
if(wordIndexArray[i]==null)continue;
ret+="<h2><b>"+POfS[i]+".</h2><b>";
List<IWordID> temp = wordIndexArray[i].getWordIDs();
for(int j=0;j<temp.size();++j){
IWordID wordID = temp.get(j);
ISynset synset = dict.getWord(wordID).getSynset();
String gloss = synset.getGloss();
ret+="<li>"+parseMean(gloss)+parseSynset(synset)+parseExample(gloss,i,j)+"</li>";
}
}
ret+="</body></html>";
return ret;
}
示例5: runWord
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
public static void runWord(WordnetRulesSource wns, IIndexWord iw1,
StringBuilder bs) {
for (int i = 0; i < iw1.getWordIDs().size(); i++) {
ISynsetID synsetID = iw1.getWordIDs().get(i).getSynsetID();
ISynset synset = wns.dictionary().getSynset(synsetID);
List<ISynsetID> hypernymsSynset = synset
.getRelatedSynsets(Pointer.HYPONYM);
for (ISynsetID sid : hypernymsSynset) {
List<IWord> iws = wns.dictionary().getSynset(sid).getWords();
for (IWord iw : iws) {
List<IWordID> x = iw.getRelatedWords();
for (IWordID xx : x)
bs.append(xx.getLemma().replace("_", " ") + "\n");
bs.append(iw.getLemma().replace("_", " ") + "\n");
}
}
}
}
示例6: getSortedSynsetsOf
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
public List<Synset> getSortedSynsetsOf(String lemma, WordNetPartOfSpeech partOfSpeech) throws WordNetException
{
List<Synset> synsets = new ArrayList<Synset>();
IIndexWord idxWord = jwiRealDictionary.getIndexWord (lemma, JwiUtils.getJwiPartOfSpeec(partOfSpeech));
if (idxWord != null)
{
List<IWordID> wordIDs = idxWord.getWordIDs();
for (IWordID wordID : wordIDs)
{
IWord word = jwiRealDictionary.getWord(wordID);
if (word == null)
throw new WordNetException("Internal error: got this wordID " + wordID + " from the JWI dictionary, but the dictionary didn't find a word for it");
ISynset jwiRealSynset = word.getSynset ();
synsets.add(getSynset(jwiRealSynset));
}
}
return synsets;
}
示例7: getRealSynsets
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
/**
* @param lemma
* @param pos
* @return
* @throws WordNetException
*/
protected ISynset[] getRealSynsets(String lemma, WordNetPartOfSpeech pos) throws WordNetException {
IIndexWord idxWord = jwiRealDictionary.getIndexWord (lemma, JwiUtils.getJwiPartOfSpeec(pos));
ISynset[] realSynsets ;
if (idxWord != null)
{
List<IWordID> wordIDs = idxWord.getWordIDs();
realSynsets = new ISynset[wordIDs.size()];
int i = 0;
for (IWordID wordID : wordIDs)
{
IWord iWord = jwiRealDictionary.getWord(wordID);
if (iWord == null)
throw new WordNetException("Internal error: got this wordID " + wordID + " from the JWI dictionary, but the dictionary didn't find a word for it");
ISynset jwiRealSynset = iWord.getSynset ();
realSynsets[i++] = jwiRealSynset;
}
}
else // there is no synset matching <lemma, pos>
realSynsets = new ISynset[0];
return realSynsets;
}
示例8: getLooseCousinsForRealSynset
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
/**
* Get all the cousin synsets of the given iSynsets, according to the loose definition, by which a cousin of a synset to the n-th degree is any synset that
* shares a hypernym, reachable by a hypernym path of length n (and possibly by other shorter and/or longer paths as well). Also, a cousin of a set of synsets
* is a cousin of AT LEAST one of the synsets in the set.
*
* @param iSynsets
* @param degree
* @return
*/
Set<String> getLooseCousinsForRealSynset(ISynset[] iSynsets, int degree) {
Set<String> cousinLemmas = new HashSet<String>();
if (iSynsets != null && iSynsets.length > 0)
{
POS pos = iSynsets[0].getPOS();
if (pos.equals(POS.NOUN) || pos.equals(POS.VERB)) // only nouns and verbs have hypernyms
{
Set<ISynsetID> remoteCousinSynsetIDs = computeRemoteCousinSynsetIDs(iSynsets, degree);
// collect the lemmas
cousinLemmas = getWordsOfSynsetIDs(remoteCousinSynsetIDs);
// screen out the original synset's lemmas
Set<String> originalSynsetLemmas = getWordsOfSynsets(iSynsets);
cousinLemmas.removeAll(originalSynsetLemmas);
}
}
return cousinLemmas;
}
示例9: findRelatedSynsetsAtLooseDistance
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
/**
* get all the synsets that are at the end of a 'relation' type path of length 'degree' from any one of the given synsetIDs. We don't care that these paths
* be minimal
* @param remoteHypernymIDs
* @param relation must be a transitive relation like hypernym or hyponym
* @param degree
* @return
*/
private Set<ISynsetID> findRelatedSynsetsAtLooseDistance( Set<ISynsetID> remoteHypernymIDs, Pointer relation, int degree) {
Set<ISynsetID> neighborIDs = remoteHypernymIDs;
for(int depth = 0; depth < degree; depth++)
{
Set<ISynsetID> secondaryNeighborIDs = new HashSet<ISynsetID>();
for (ISynsetID neighborID : neighborIDs)
{
ISynset neighbor = jwiDictionary.jwiRealDictionary.getSynset(neighborID);
for (ISynsetID secondaryNeighborID : neighbor.getRelatedSynsets(relation))
secondaryNeighborIDs.add(secondaryNeighborID);
}
neighborIDs = secondaryNeighborIDs;
}
return neighborIDs;
}
示例10: findRelatedSynsetsAtExactDistance
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
/**
* @param relation must be a transitive relation like hypernym or hyponym
* @param degree
* @param initialSynsetIDs
* @return
*/
private Set<ISynsetID> findRelatedSynsetsAtExactDistance( Set<ISynsetID> initialSynsetIDs, Pointer relation, int degree) {
Set<ISynsetID> neighborIDs = new HashSet<ISynsetID>(initialSynsetIDs);
Set<ISynsetID> visitedIDs = new HashSet<ISynsetID>(initialSynsetIDs);;
for(int depth = 0; depth < degree; depth++)
{
Set<ISynsetID> secondaryNeighborIDs = new HashSet<ISynsetID>();
for (ISynsetID neighborID : neighborIDs)
{
ISynset neighbor = jwiDictionary.jwiRealDictionary.getSynset(neighborID);
for (ISynsetID secondaryNeighborID : neighbor.getRelatedSynsets(relation))
// if we haven't visited this hypernym yet, add it
if (!visitedIDs.contains(secondaryNeighborID))
{
secondaryNeighborIDs.add(secondaryNeighborID);
visitedIDs.add(secondaryNeighborID);
}
}
neighborIDs = secondaryNeighborIDs;
}
return neighborIDs;
}
示例11: mapOffsetToReadableForm
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
public String mapOffsetToReadableForm(String offset, String word, POS tag)
{
List<IWord> senses = getSenses(word, tag);
ISynset syn = getSynsetFromOffset(offset);
int senseRank = 1;
for(IWord sense : senses)
{
if(sense.getSynset() == syn)
break;
senseRank++;
}
if(senseRank > senses.size())
{
log.warn("[ERROR: could not generate the readable form for "+word+" "+offset);
return "null";
}
return word+"."+senseRank;
}
示例12: findClosestCommonParent
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
private ISynset findClosestCommonParent(List<ISynset> pathToRoot1,
List<ISynset> pathToRoot2) {
int i = 0;
int j = 0;
if (pathToRoot1.size() > pathToRoot2.size()) {
i = pathToRoot1.size() - pathToRoot2.size();
j = 0;
} else if (pathToRoot1.size() < pathToRoot2.size()) {
i = 0;
j = pathToRoot2.size() - pathToRoot1.size();
}
do {
ISynset synset1 = pathToRoot1.get(i++);
ISynset synset2 = pathToRoot2.get(j++);
if (synset1.equals(synset2)) {
return synset1;
}
} while (i < pathToRoot1.size());
return null;
}
示例13: maxDepth
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
/**
* maxDepth
*
* @param synset
* @return The length of the longest hypernym path from this synset to the
* root.
*/
public int maxDepth(ISynset synset) {
if (synset == null) {
return 0;
}
List<ISynsetID> ancestors = getAncestors(synset);
if (ancestors.isEmpty()) {
return 0;
}
int i = 0;
for (ISynsetID ancestor : ancestors) {
ISynset ancestorSynset = m_dict.getSynset(ancestor);
int j = maxDepth(ancestorSynset);
i = (i > j) ? i : j;
}
return i + 1;
}
示例14: shortestPathDistance
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
/**
* Shortest Path Distance
*
* Returns the distance of the shortest path linking the two synsets (if one
* exists).
*
* For each synset, all the ancestor nodes and their distances are recorded
* and compared. The ancestor node common to both synsets that can be reached
* with the minimum number of traversals is used. If no ancestor nodes are
* common, null is returned. If a node is compared with itself 0 is returned.
*
* @param synset1
* @param synset2
* @return The number of edges in the shortest path connecting the two nodes,
* or null if no path exists.
*/
public Integer shortestPathDistance(ISynset synset1, ISynset synset2) {
Integer distance = null;
if (synset1.equals(synset2)) {
return 0;
}
ISynset ccp = findClosestCommonParent(synset1, synset2);
if (ccp != null) {
distance = maxDepth(synset1) + maxDepth(synset2) - 2 * maxDepth(ccp);
// Debug
String w1 = synset1.getWords().get(0).getLemma();
String w2 = synset2.getWords().get(0).getLemma();
String w3 = ccp.getWords().get(0).getLemma();
System.out.println("maxDepth(" + w1 + "): " + maxDepth(synset1));
System.out.println("maxDepth(" + w2 + "): " + maxDepth(synset2));
System.out.println("maxDepth(" + w3 + "): " + maxDepth(ccp));
System.out.println("distance(" + w1 + "," + w2 + "): " + distance);
}
return distance;
}
示例15: similarity
import edu.mit.jwi.item.ISynset; //导入依赖的package包/类
/**
* Computes a score denoting how similar two word senses are, based on the
* shortest path that connects the senses in the is-a (hypernym/hypnoym)
* taxonomy.
*
* @param indexWord1
* @param indexWord2
* @return Returns a similarity score is in the range 0 to 1. A score of 1
* represents identity i.e. comparing a sense with itself will return
* 1.
*/
public double similarity(String word1String, POS word1POS,
String word2String, POS word2POS) {
IIndexWord indexWord1 = getIndexWord(word1String, word1POS);
Set<ISynset> synsets1 = getSynsets(indexWord1);
IIndexWord indexWord2 = getIndexWord(word2String, word2POS);
Set<ISynset> synsets2 = getSynsets(indexWord2);
double maxSim = 0;
for (ISynset synset1 : synsets1) {
for (ISynset synset2 : synsets2) {
double sim = pathSimilarity(synset1, synset2);
if ((sim > 0) && (sim > maxSim)) {
maxSim = sim;
}
}
}
return maxSim;
}