本文整理汇总了Java中edu.mit.jwi.item.ISynsetID类的典型用法代码示例。如果您正苦于以下问题:Java ISynsetID类的具体用法?Java ISynsetID怎么用?Java ISynsetID使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ISynsetID类属于edu.mit.jwi.item包,在下文中一共展示了ISynsetID类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractLastHypernym
import edu.mit.jwi.item.ISynsetID; //导入依赖的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.ISynsetID; //导入依赖的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.ISynsetID; //导入依赖的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: fillList
import edu.mit.jwi.item.ISynsetID; //导入依赖的package包/类
Set<String> fillList(Pointer ptype,Map<IPointer, List<IWordID>> wordMap,Map<IPointer, List<ISynsetID>> synMap){
Set<String> ts;
List<IWordID> tw;
List<ISynsetID> tsy;
ts = new TreeSet<String>();
tw = wordMap.get(ptype);
if(tw!=null){
for(IWordID wid:tw){
String tempString = wid.getLemma();
if(tempString!=null)ts.add(tempString);
}
}
tsy = synMap.get(ptype);
if(tsy!=null){
for(ISynsetID sid:tsy){
List<IWord> t = dict.getSynset(sid).getWords();
if(t!=null)
for(IWord w:t){
ts.add(w.getLemma());
}
}
}
if(!ts.isEmpty())return ts;
return null;
}
示例5: runWord
import edu.mit.jwi.item.ISynsetID; //导入依赖的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: getLooseCousinsForRealSynset
import edu.mit.jwi.item.ISynsetID; //导入依赖的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;
}
示例7: findRelatedSynsetsAtLooseDistance
import edu.mit.jwi.item.ISynsetID; //导入依赖的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;
}
示例8: findRelatedSynsetsAtExactDistance
import edu.mit.jwi.item.ISynsetID; //导入依赖的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;
}
示例9: maxDepth
import edu.mit.jwi.item.ISynsetID; //导入依赖的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;
}
示例10: getMeanings
import edu.mit.jwi.item.ISynsetID; //导入依赖的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;
}
示例11: ExtractHypernymWord
import edu.mit.jwi.item.ISynsetID; //导入依赖的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;
}
示例12: getHyperSet
import edu.mit.jwi.item.ISynsetID; //导入依赖的package包/类
private Set<ISynset> getHyperSet(Set<ISynset> set) {
Set<ISynset> hyperSet = new HashSet<>();
for (ISynset syn : set) {
List<ISynsetID> hyperIDs = syn.getRelatedSynsets(Pointer.HYPERNYM);
if (!hyperIDs.isEmpty()) {
for (ISynsetID hyperID : hyperIDs) { hyperSet.add(dict.getSynset(hyperID)); }
}
}
return hyperSet;
}
示例13: getHypernyms
import edu.mit.jwi.item.ISynsetID; //导入依赖的package包/类
/**
* Retrieve a set of hypernyms for a word. Use only the first sense if
* useFirstSense flag is true.
*/
public static HashSet<String> getHypernyms(IDictionary dict, String word, String posTag, boolean firstSenseOnly) {
HashSet<String> hypernyms = new HashSet<String>();
POS pos = POS.getPartOfSpeech(posTag.charAt(0));
if (pos == null) {
return hypernyms;
}
IIndexWord iIndexWord = dict.getIndexWord(word, pos);
if (iIndexWord == null) {
return hypernyms; // no senses found
}
// iterate over senses
for (IWordID iWordId : iIndexWord.getWordIDs()) {
IWord iWord1 = dict.getWord(iWordId);
ISynset iSynset = iWord1.getSynset();
// multiple hypernym chains are possible for a synset
for (ISynsetID iSynsetId : iSynset.getRelatedSynsets(Pointer.HYPERNYM)) {
List<IWord> iWords = dict.getSynset(iSynsetId).getWords();
for (IWord iWord2 : iWords) {
String lemma = iWord2.getLemma();
hypernyms.add(lemma.replace(' ', '_')); // also get rid of
// spaces
}
}
if (firstSenseOnly) {
break;
}
}
return hypernyms;
}
示例14: getHyperHypernyms
import edu.mit.jwi.item.ISynsetID; //导入依赖的package包/类
public static HashSet<String> getHyperHypernyms(IDictionary dict, String word, String posTag,
boolean firstSenseOnly) {
HashSet<String> hypernyms = new HashSet<String>();
POS pos = POS.getPartOfSpeech(posTag.charAt(0));
if (pos == null) {
return hypernyms;
}
IIndexWord iIndexWord = dict.getIndexWord(word, pos);
if (iIndexWord == null) {
return hypernyms; // no senses found
}
// iterate over senses
for (IWordID iWordId : iIndexWord.getWordIDs()) {
IWord iWord1 = dict.getWord(iWordId);
ISynset iSynset = iWord1.getSynset();
for (ISynsetID iSynsetId1 : iSynset.getRelatedSynsets(Pointer.HYPERNYM)) {
for (ISynsetID iSynsetId2 : dict.getSynset(iSynsetId1).getRelatedSynsets(Pointer.HYPERNYM)) {
List<IWord> iWords = dict.getSynset(iSynsetId2).getWords();
for (IWord iWord2 : iWords) {
String lemma = iWord2.getLemma();
hypernyms.add(lemma.replace(' ', '_')); // also get rid
// of spaces
}
}
}
if (firstSenseOnly) {
break;
}
}
return hypernyms;
}
示例15: hrefToSynsetId
import edu.mit.jwi.item.ISynsetID; //导入依赖的package包/类
/**
* The first digit of the synset identifies the part-of-speech according to the following table
Part-of-speech Letter code Numeric code
Noun n 1
Verb v 2
Adjective a 3
Adverb r 4
Adjective Satellite s 3
Phrase p 4
* @param href Format must be either "yago:wordnet_[word]_[synsetId]" or "wn30:[8digit]-[pos]".
* Synset ID in WordNet 3.1 format (but we're still using WordNet 3.0 data).
* Example: "yago:wordnet_entity_100001740".
* @return
*/
public ISynsetID hrefToSynsetId(String href) {
final String nsPrefix = StringUtils.substringBefore(href, ":");
final String synsetId;
if ("yago".equals(nsPrefix)) {
final String digits9 = StringUtils.substringAfterLast(href, "_");
final char numeric = digits9.charAt(0);
final char pos;
switch (numeric) {
case '1':
pos = 'n';
break;
case '2':
pos = 'v';
break;
case '3':
pos = 'a';
break; // TODO: can be 'a' or 's' !
case '4':
pos = 'r';
break; // TODO: can be 'r' or 'p' !
default:
throw new ReasonerException("Unknown WordNet QName: " + href);
}
synsetId = "SID-" + digits9.substring(1, digits9.length()) + "-" + Character.toUpperCase(pos);
} else if ("wn30".equals(nsPrefix)) {
synsetId = "SID-" + StringUtils.substringAfter(href, ":").toUpperCase();
} else {
throw new ReasonerException("Unknown nsPrefix: " + nsPrefix);
}
try {
return SynsetID.parseSynsetID(synsetId);
} catch (Exception e) {
throw new ReasonerException(e, "Cannot parse synset '%s'", synsetId);
}
}