当前位置: 首页>>代码示例>>Java>>正文


Java POS类代码示例

本文整理汇总了Java中net.didion.jwnl.data.POS的典型用法代码示例。如果您正苦于以下问题:Java POS类的具体用法?Java POS怎么用?Java POS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


POS类属于net.didion.jwnl.data包,在下文中一共展示了POS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: synonymsOf

import net.didion.jwnl.data.POS; //导入依赖的package包/类
/**
   * @param token A token from the domain e.g. "v-kidnap"
   * @return A list of synonyms (with "v-" attached)
   */
  private List<String> synonymsOf(String token) {
    POS pos = POS.VERB;
    if( token.startsWith("n") ) pos = POS.NOUN;
    String header = token.substring(0, 2);
    
    // Get the synsets.
    Synset[] synsets = _wordnet.synsetsOf(token.substring(2), pos);
    
    // Get all words in all synsets.
    List<String> synonyms = new ArrayList<String>();
    if( synsets != null ) {
      for( Synset synset : synsets ) {
        List<String> syms = _wordnet.wordsInSynset(synset);
//        System.out.println("  token " + token + " synset " + synset + ": " + syms);
        for( String sym : syms ) {
          String strtoken = header + sym;
          if( !synonyms.contains(strtoken) )
            synonyms.add(strtoken);
        }
      }
    }
    return synonyms;
  }
 
开发者ID:nchambers,项目名称:schemas,代码行数:28,代码来源:LabelDocument.java

示例2: areSiblings

import net.didion.jwnl.data.POS; //导入依赖的package包/类
/**
 * Returns true if the two tokens are under the same immediate synset (siblings).
 * @param token1 A token.
 * @param token2 A token.
 * @param postag The POS tag of both tokens.
 * @return True if the tokens are siblings, false otherwise.
 */
public boolean areSiblings(String token1, String token2, POS postag) {
  Synset[] synsets1 = synsetsOf(token1, postag);
  Synset[] synsets2 = synsetsOf(token2, postag);
  if( synsets1 != null && synsets2 != null ) {
    for( int i = 0; i < synsets1.length; i++ ) {
      Synset syn = synsets1[i];
      for( int j = 0; j < synsets2.length; j++ ) {
        if( syn == synsets2[j] )
          return true;
      }
    }
  }
  if( (token1.equals("hurt") && token2.equals("injure")) || (token1.equals("injure") && token2.equals("hurt"))  )
    System.out.println("areSiblings returning false!");
  return false;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:24,代码来源:WordNet.java

示例3: isNounPersonOrGroup

import net.didion.jwnl.data.POS; //导入依赖的package包/类
public boolean isNounPersonOrGroup(String token, boolean mainSynsetOnly, boolean justPerson) {
  if( _isPersonOrGroup == null ) _isPersonOrGroup = new HashMap<String, Boolean>();
  if( _isPersonOrGroup.containsKey(token) ) return _isPersonOrGroup.get(token);

  Synset[] synsets = synsetsOf(token, POS.NOUN);
  if( synsets == null ) {
  }
  else {
    for( Synset synset : synsets ) {
      List<Synset> chain = hypernymChainKeepChild(synset);
      if( chain != null ) {
        for( Synset parent : chain ) {
          if( isPersonSynset(parent) || (!justPerson && isSocialGroupSynset(parent)) ) {
            _isPersonOrGroup.put(token, true);
            return true;
          }
        }
      }
      // Stop now if we are only checking the main synset.
      if( mainSynsetOnly ) return false;
    }
  }
  _isPersonOrGroup.put(token, false);
  return false;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:26,代码来源:WordNet.java

示例4: isTime

import net.didion.jwnl.data.POS; //导入依赖的package包/类
public boolean isTime(String token) {
    if( _isTime == null ) _isTime = new HashMap<String, Boolean>();
    if( _isTime.containsKey(token) ) return _isTime.get(token);

    Synset[] synsets = synsetsOf(token, POS.NOUN);
//    System.out.println("isTime top " + token);
    if( synsets == null ) {
//      System.out.println("isTime null synsets: " + token);
    }
    else {
      for( Synset synset : synsets ) {
        List<Synset> chain = hypernymChainKeepChild(synset);
        if( chain != null ) {
          for( Synset parent : chain ) {
            if( isTimeSynset(parent) ) {
              _isTime.put(token, true);
              return true;
            }
          }
        }
      }
    }
    _isTime.put(token, false);
    return false;
  }
 
开发者ID:nchambers,项目名称:probschemas,代码行数:26,代码来源:WordNet.java

示例5: isLocation

import net.didion.jwnl.data.POS; //导入依赖的package包/类
public boolean isLocation(String token) {
  if( _isLocation == null ) _isLocation = new HashMap<String, Boolean>();
  if( _isLocation.containsKey(token) ) return _isLocation.get(token);

  Synset[] synsets = synsetsOf(token, POS.NOUN);
  //    System.out.println("isNounEntity top " + token);
  if( synsets == null ) {
    //      System.out.println("isNounEntity null synsets: " + token);
  }
  else {
    for( Synset synset : synsets ) {
      List<Synset> chain = hypernymChainKeepChild(synset);
      if( chain != null ) {
        for( Synset parent : chain ) {
          if( isLocationSynset(parent) ) {
            _isLocation.put(token, true);
            return true;
          }
        }
      }
    }
  }
  _isLocation.put(token, false);
  return false;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:26,代码来源:WordNet.java

示例6: isInteger

import net.didion.jwnl.data.POS; //导入依赖的package包/类
/**
 * Assumes the given token is a noun.
 * @return true if the token has a synset with an ancestor that is Integer
 */
public boolean isInteger(String token) {
  Synset[] synsets = synsetsOf(token, POS.NOUN);
  //    System.out.println("isNounEntity top " + token);
  if( synsets == null ) {
    //      System.out.println("isNounEntity null synsets: " + token);
  }
  else {
    for( Synset synset : synsets ) {
      List<Synset> chain = hypernymChainKeepChild(synset);
      if( chain != null ) {
        for( Synset parent : chain ) {
          //	    System.out.println(parent);
          Word[] words = parent.getWords();
          if( (words.length > 0 && words[0].getLemma().equals("integer")) )
            return true;
        }
      }
    }
  }
  return false;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:26,代码来源:WordNet.java

示例7: isPhysicalObject

import net.didion.jwnl.data.POS; //导入依赖的package包/类
/**
 * Assumes the given token is a noun.
 * @return true if the token has a synset with an ancestor that is a physical object
 *         synset.
 */
public boolean isPhysicalObject(String token) {
  if( _isPhysicalObject == null ) _isPhysicalObject = new HashMap<String, Boolean>();
  if( _isPhysicalObject.containsKey(token) ) return _isPhysicalObject.get(token);

  Synset[] synsets = synsetsOf(token, POS.NOUN);
  if( synsets == null ) {
  }
  else {
    for( Synset synset : synsets ) {
      List<Synset> chain = hypernymChainKeepChild(synset);
      if( chain != null ) {
        for( Synset parent : chain ) {
          if( isPhysicalObjectSynset(parent) ) {
            _isPhysicalObject.put(token, true);
            return true;
          }
        }
      }
    }
  }
  _isPhysicalObject.put(token, false);
  return false;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:29,代码来源:WordNet.java

示例8: isMaterial

import net.didion.jwnl.data.POS; //导入依赖的package包/类
/**
   * Assumes the given token is a noun.
   * WordNet does not put material (explosive, rocks, dust, fiber, etc.) under "physical objects".
   * @return true if the token has a synset with an ancestor that is a "material" synset.
   *       
   */
  public boolean isMaterial(String token) {
    if( _isMaterial == null ) _isMaterial = new HashMap<String, Boolean>();
    if( _isMaterial.containsKey(token) ) return _isMaterial.get(token);

    Synset[] synsets = synsetsOf(token, POS.NOUN);
//    System.out.println("isMatter top " + token);
    if( synsets == null ) {
    }
    else {
      for( Synset synset : synsets ) {
        List<Synset> chain = hypernymChainKeepChild(synset);
        if( chain != null ) {
          for( Synset parent : chain ) {
            Word[] words = parent.getWords();
            if( words.length >= 1 && words[0].getLemma().equals("material") ) {
              _isMaterial.put(token, true);
              return true;
            }
          }
        }
      }
    }
    _isMaterial.put(token, false);
    return false;
  }
 
开发者ID:nchambers,项目名称:probschemas,代码行数:32,代码来源:WordNet.java

示例9: isNamedEntity

import net.didion.jwnl.data.POS; //导入依赖的package包/类
/**
 * Assumes the given token is a noun.
 * @return true if the token only has "instance hypernym" links from its synsets.
 *              If it has a normal "hypernym", or is unknown, then return false.
 */
public boolean isNamedEntity(String token) {
  // save time with a table lookup
  if( _isNamedEntity == null ) _isNamedEntity = new HashMap<String, Boolean>();
  if( _isNamedEntity.containsKey(token) ) return _isNamedEntity.get(token);

  Synset[] synsets = synsetsOf(token, POS.NOUN);
  //    System.out.println("isNounEvent top " + token);
  if( synsets == null ) {
    //      System.out.println("isNounEvent null synsets: " + token);
  }
  else {
    for( Synset synset : synsets ) {
      if( !hasHypernymInstance(synset) ) {
        _isNamedEntity.put(token, false);
        return false;
      }
    }
    _isNamedEntity.put(token, true);
    return true;
  }
  _isNamedEntity.put(token, false);
  return false;
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:29,代码来源:WordNet.java

示例10: stringTypes

import net.didion.jwnl.data.POS; //导入依赖的package包/类
/**
 * Lookup the word in WordNet
 * @returns Array of three strings: word, lemma, synset
 */
public static String[] stringTypes(String str) {
  try {
    String[] types = new String[3];
    String[] parts = str.split("\\s+");
    IndexWord iword = Dictionary.getInstance().lookupIndexWord(POS.VERB, parts[parts.length-1]);
    if( iword == null ) 
      iword = Dictionary.getInstance().lookupIndexWord(POS.NOUN, parts[parts.length-1]);
    if( iword == null ) {
      types[1] = parts[parts.length-1];
      types[2] = "-1";
    }
    else {
      String lemma = iword.getLemma();
      if( lemma.indexOf(' ') != -1 ) // Sometimes it returns a two word phrase
        lemma = lemma.trim().replace(' ','-');
      types[1] = lemma;
      types[2] = Long.toString(iword.getSense(1).getOffset());
    }
    types[0] = parts[parts.length-1];
    return types;
  } catch( Exception ex ) { ex.printStackTrace(); return null; }
}
 
开发者ID:nchambers,项目名称:probschemas,代码行数:27,代码来源:WordNet.java

示例11: getSingleEventTokenFeatures

import net.didion.jwnl.data.POS; //导入依赖的package包/类
/**
 * Create token/lemma/synset features for an event.
 * @param eventIndex Either 1 or 2, the first or second event in your link. This differentiates the feature names.
 */
private Counter<String> getSingleEventTokenFeatures(int eventIndex, TextEvent event1, List<Tree> trees) {
  Counter<String> feats = new ClassicCounter<String>();
  
  String token = event1.string();
  String postag = TreeOperator.indexToPOSTag(trees.get(event1.sid()), event1.index());
  String lemma = _wordnet.lemmatizeTaggedWord(token, postag);

  // Token and Lemma
  feats.incrementCount("token" + eventIndex + "-" + token);
  feats.incrementCount("lemma" + eventIndex + "-" + lemma);
  
  // WordNet synset
  Synset[] synsets = null;
  if( postag.startsWith("VB") )
    synsets = _wordnet.synsetsOf(token, POS.VERB);
  else if( postag.startsWith("NN") )
    synsets = _wordnet.synsetsOf(token, POS.NOUN);
  if( synsets != null && synsets.length > 0 )
    feats.incrementCount("synset" + eventIndex + "-" + synsets[0].getOffset());
  
  return feats;
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:27,代码来源:TLinkFeaturizer.java

示例12: isVerb

import net.didion.jwnl.data.POS; //导入依赖的package包/类
/**
 * @param word A Word
 * @return True if the word can be a verb according to WordNet
 */
private boolean isVerb(String word) {
  // save time with a table lookup
  if( wordToVerb.containsKey(word) )
    return wordToVerb.get(word);

  try {
    IndexWord iword = Dictionary.getInstance().lookupIndexWord(POS.VERB, word);

    if( iword == null ) {
      wordToVerb.put(word, false);
      return false;
    }
    else {
      wordToVerb.put(word, true);
      return true;
    }
  } catch( Exception ex ) { ex.printStackTrace(); }

  return false;
}
 
开发者ID:nchambers,项目名称:schemas,代码行数:25,代码来源:BasicEventAnalyzer.java

示例13: getJwnlPartOfSpeec

import net.didion.jwnl.data.POS; //导入依赖的package包/类
static POS getJwnlPartOfSpeec(WordNetPartOfSpeech partOfSpeech)
{
	switch(partOfSpeech)
	{
	case ADJECTIVE:
		return POS.ADJECTIVE;
	case ADVERB:
		return POS.ADVERB;
	case NOUN:
		return POS.NOUN;
	case VERB:
		return POS.VERB;
	default:
		return null;
	}
}
 
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:17,代码来源:JwnlUtils.java

示例14: getSynset

import net.didion.jwnl.data.POS; //导入依赖的package包/类
private Synset getSynset(POS pos, long offset, String line) throws JWNLException {
	POSKey key = new POSKey(pos, offset);
	Synset synset = getCachedSynset(key);
       if (synset == null) {
           try {
               if (line == null) {
                   line = getFileManager().readLineAt(pos, DictionaryFileType.DATA, offset);
               }
               synset = _factory.createSynset(pos, line);
               synset.getWords();
               
               if (synset != null) {
                   cacheSynset(key, synset);
               }
           } catch (IOException e) {
               throw new JWNLException("DICTIONARY_EXCEPTION_005", new Long(offset), e);
           }
       }
	return synset;
}
 
开发者ID:duguyue100,项目名称:chomsky,代码行数:21,代码来源:FileBackedDictionary.java

示例15: lookupBase

import net.didion.jwnl.data.POS; //导入依赖的package包/类
public String lookupBase(String pos, String word)
{
	String can="";
	try
	{
		if (pos.equals("VERB"))
			can=wordnet.lookupIndexWord(POS.VERB, word).getLemma();
		else if (pos.equals("ADJECTIVE"))
			can=wordnet.lookupIndexWord(POS.ADJECTIVE, word).getLemma();
		else if (pos.equals("NOUN"))
			can=wordnet.lookupIndexWord(POS.NOUN, word).getLemma();
		else if (pos.equals("ADVERB"))
			can=wordnet.lookupIndexWord(POS.ADVERB, word).getLemma();
	}
	catch(Exception ex)
	{
		//System.out.println("word wrong");
	}
	
	return can;
}
 
开发者ID:duguyue100,项目名称:chomsky,代码行数:22,代码来源:ChomskyText.java


注:本文中的net.didion.jwnl.data.POS类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。