de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS.getPosValue()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(84)

本文整理了Java中de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS.getPosValue()方法的一些代码示例,展示了POS.getPosValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。POS.getPosValue()方法的具体详情如下:
包路径:de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS
类名称:POS
方法名:getPosValue

POS.getPosValue介绍

[英]getter for PosValue - gets Fine-grained POS tag. This is the tag as produced by a POS tagger or obtained from a reader.
[中]获取细粒度的POS标记。这是POS标签工制作的标签或从读卡器获取的标签。

代码示例

代码示例来源:origin: oaqa/knn4qa

/**
  * Annotates the CAS and checks if it's good quality.
  * 
  * @param jcas            An input CAS that will be annotated.
  * @param minTokQty       The minimum number of tokens present to be considered good.
  * @return                true if the CAS contains a high-quality text. 
  * @throws AnalysisEngineProcessException
  */
 public static boolean checkCAS(JCas jcas, int minTokQty) throws AnalysisEngineProcessException {       
  boolean hasNoun = false, hasVerb = false;
  
  for (POS p: JCasUtil.select(jcas, POS.class)) {
   if (p.getPosValue().startsWith("NN")) hasNoun = true;
   if (p.getPosValue().startsWith("VB")) hasVerb = true;
  }
  
  Collection<Token> toks = JCasUtil.select(jcas, Token.class);
  
  return toks.size() >= minTokQty && hasNoun && hasVerb;    
 }  
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.api.segmentation-asl

/**
 * @return the POS value if there is a {@link POS} annotation linked to this token.
 */
public String getPosValue()
{
  POS pos = getPos();
  return pos != null ? pos.getPosValue() : null;
}

代码示例来源:origin: de.unidue.ltl.flextag/flextag-core

public String getTextClassificationOutcome(JCas jcas, TextClassificationTarget target)
{
  List<POS> posList = JCasUtil.selectCovered(jcas, POS.class, target);
  String outcome = "";
  if (useCoarseGrained) {
    outcome = posList.get(0).getClass().getSimpleName();
  }
  else {
    outcome = posList.get(0).getPosValue();
  }
  return outcome;
}

代码示例来源:origin: dkpro/dkpro-tc

public String getTextClassificationOutcome(JCas jcas, TextClassificationTarget aTarget)
{
  List<POS> posList = JCasUtil.selectCovered(jcas, POS.class, aTarget);
  return posList.get(0).getPosValue();
}

代码示例来源:origin: org.dkpro.similarity/dkpro-similarity-algorithms-structure-asl

private Set<List<String>> getPosNGrams(List<POS> pos)
{
  Set<List<String>> ngrams = new HashSet<List<String>>();
  
  for (int i = 0; i < pos.size() - (n - 1); i++)
  {
    // Generate n-gram at index i
    List<String> ngram = new ArrayList<String>();
    for (int k = 0; k < n; k++)
    {
      String token = pos.get(i + k).getPosValue();
      ngram.add(token);
    }
    
    // Add
    ngrams.add(ngram);
  }
  
  return ngrams;
}

代码示例来源:origin: dkpro/dkpro-core

/**
 * @return the POS value if there is a {@link POS} annotation linked to this token.
 */
public String getPosValue()
{
  POS pos = getPos();
  return pos != null ? pos.getPosValue() : null;
}

代码示例来源:origin: dkpro/dkpro-tc

public String getTextClassificationOutcome(JCas jcas, TextClassificationTarget unit)
{
  List<POS> posList = JCasUtil.selectCovered(jcas, POS.class, unit);
  return posList.get(0).getPosValue().replaceAll(" ", "_");
}

代码示例来源:origin: dkpro/dkpro-similarity

private Set<List<String>> getPosNGrams(List<POS> pos)
{
  Set<List<String>> ngrams = new HashSet<List<String>>();
  
  for (int i = 0; i < pos.size() - (n - 1); i++)
  {
    // Generate n-gram at index i
    List<String> ngram = new ArrayList<String>();
    for (int k = 0; k < n; k++)
    {
      String token = pos.get(i + k).getPosValue();
      ngram.add(token);
    }
    
    // Add
    ngrams.add(ngram);
  }
  
  return ngrams;
}

代码示例来源:origin: de.tudarmstadt.ukp.similarity.algorithms/de.tudarmstadt.ukp.similarity.algorithms.structure-asl

private Set<List<String>> getPosNGrams(List<POS> pos)
{
  Set<List<String>> ngrams = new HashSet<List<String>>();
  
  for (int i = 0; i < pos.size() - (n - 1); i++)
  {
    // Generate n-gram at index i
    List<String> ngram = new ArrayList<String>();
    for (int k = 0; k < n; k++)
    {
      String token = pos.get(i + k).getPosValue();
      ngram.add(token);
    }
    
    // Add
    ngrams.add(ngram);
  }
  
  return ngrams;
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.features.ngram-asl

public static FrequencyDistribution<String> getDocumentPosNgrams(JCas jcas, int minN, int maxN, boolean useCanonical)
{
  FrequencyDistribution<String> posNgrams = new FrequencyDistribution<String>();
  for (Sentence s : select(jcas, Sentence.class)) {        
    List<String> postagstrings = new ArrayList<String>();
    for (POS p : JCasUtil.selectCovered(jcas, POS.class, s)) {
      if (useCanonical) {
        postagstrings.add(p.getClass().getSimpleName());
      }
      else {
        postagstrings.add(p.getPosValue());
      }
    }
    String[] posarray = postagstrings.toArray(new String[postagstrings.size()]);

    for (List<String> ngram : new NGramStringListIterable(posarray, minN, maxN)) {
      posNgrams.inc(StringUtils.join(ngram, NGRAM_GLUE));
    }
  }
  return posNgrams;
}

代码示例来源:origin: dkpro/dkpro-tc

private static FrequencyDistribution<String> documentBasedDistribution(JCas jcas,
    Annotation focus, boolean useCanonical, int minN, int maxN)
{
  FrequencyDistribution<String> posNgrams = new FrequencyDistribution<String>();
  List<String> postagstrings = new ArrayList<String>();
  for (POS p : selectCovered(jcas, POS.class, focus)) {
    if (useCanonical) {
      postagstrings.add(p.getClass().getSimpleName());
    }
    else {
      postagstrings.add(p.getPosValue());
    }
  }
  String[] posarray = postagstrings.toArray(new String[postagstrings.size()]);
  for (List<String> ngram : new NGramStringListIterable(posarray, minN, maxN)) {
    posNgrams.inc(StringUtils.join(ngram, NGRAM_GLUE));
  }
  return posNgrams;
}

代码示例来源:origin: hltfbk/Excitement-Open-Platform

protected Map<String, Integer> countTokenPoses(JCas text) {
  Map<String, Integer> tokenNumMap = new HashMap<String, Integer>();
  Iterator<Annotation> tokenIter = text.getAnnotationIndex(Token.type)
      .iterator();
  while (tokenIter.hasNext()) {
    Token curr = (Token) tokenIter.next();
    String tokenText = curr.getLemma().getValue().replace("#", "\\#")
        + " ### " + curr.getPos().getPosValue();
    Integer num = tokenNumMap.get(tokenText);
    if (null == num) {
      tokenNumMap.put(tokenText, 1);
    } else {
      tokenNumMap.put(tokenText, num + 1);
    }
  }
  return tokenNumMap;
}

代码示例来源:origin: dkpro/dkpro-similarity

public List<String> getSubstitutions(JCas jcas)
{
  List<String> tokens = new ArrayList<String>();
  List<String> postags = new ArrayList<String>();;
  
  for (Token t : JCasUtil.select(jcas, Token.class))
  {
    try
    {
      tokens.add(t.getLemma().getValue().toLowerCase());
      postags.add(t.getPos().getPosValue());
    }
    catch (NullPointerException e) {
      System.err.println("Couldn't read lemma value for token \"" + t.getCoveredText() + "\"");
    }
  }
  
  return getSubstitutions(tokens, postags);
}

代码示例来源:origin: dkpro/dkpro-similarity

public List<String> getSubstitutions(JCas jcas, Annotation coveringAnnotation)
{
  List<String> tokens = new ArrayList<String>();
  List<String> postags = new ArrayList<String>();;
  
  for (Token t : JCasUtil.selectCovered(jcas, Token.class, coveringAnnotation))
  {
    try
    {
      tokens.add(t.getLemma().getValue().toLowerCase());
      postags.add(t.getPos().getPosValue());
    }
    catch (NullPointerException e) {
      System.err.println("Couldn't read lemma value for token \"" + t.getCoveredText() + "\"");
    }
  }
  
  return getSubstitutions(tokens, postags);
}

代码示例来源:origin: webanno/webanno

@SuppressWarnings("unused")
private boolean hasPos(FeatureStructure fs, String posValue)
{
  if (fs instanceof POS) {
    POS pos = (POS) fs;
    if (pos.getPosValue().equals(posValue)) {
      return true;
    }
  }
  else if (fs instanceof Token) {
    Token token = (Token) fs;
    if (token.getPos().getPosValue().equals(posValue)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.testing-asl

@Override
public boolean check(JCas aJCas, List<Message> aMessages)
{
  List<Token> withoutPOS = select(aJCas, Token.class).stream()
      .filter(t -> t.getPos() == null)
      .collect(Collectors.toList());
  
  for (Token t : withoutPOS) {
    aMessages.add(new Message(this, ERROR, String.format("Token has no POS: %s [%d..%d]", t
        .getType().getName(), t.getBegin(), t.getEnd())));
  }
  List<Token> withoutPOSValue = select(aJCas, Token.class).stream()
      .filter(t -> t.getPos() != null && t.getPos().getPosValue() == null)
      .collect(Collectors.toList());
  
  for (Token t : withoutPOSValue) {
    aMessages.add(new Message(this, ERROR, String.format(
        "Token has no POS value: %s [%d..%d]", t.getType().getName(), t.getBegin(),
        t.getEnd())));
  }
  return aMessages.stream().anyMatch(m -> m.level == ERROR);
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.opennlp-asl

@Override
  public POSSample produce(JCas aJCas)
  {
    // Process present sentences
    Sentence sentence = sentences.next();
    
    // Block on next call to read
    if (!sentences.hasNext()) {
      documentComplete();
    }
    
    List<String> words = new ArrayList<>();
    List<String> tags = new ArrayList<>();
    
    for (Token t : selectCovered(Token.class, sentence)) {
      words.add(t.getText());
      if (t.getPos() == null) {
        throw new IllegalStateException("Token [" + t.getText() + "] has no POS");
      }
      tags.add(t.getPos().getPosValue());
    }
    
    return new POSSample(words, tags);
  }
}

代码示例来源:origin: hltfbk/Excitement-Open-Platform

protected Map<String, String> indexLemmaDepTree(JCas text) {
    Map<String, String> depTree = new HashMap<String, String>();

    for (Dependency dep : JCasUtil.select(text, Dependency.class)) {
      Token child = dep.getDependent();
      Token parent = dep.getGovernor();
      depTree.put(child.getBegin() + " ### "
          + child.getLemma().getValue().replace("#", "\\#") + " ### "
          + child.getPos().getPosValue(), dep.getDependencyType()
          + " ## " + parent.getBegin() + " ### "
          + parent.getLemma().getValue().replace("#", "\\#")
          + " ### " + parent.getPos().getPosValue());
    }

    return depTree;
  }
}

代码示例来源:origin: hltfbk/Excitement-Open-Platform

private static NodeInfo buildNodeInfo(JCas jcas, Token tokenAnno, int serial) throws CasTreeConverterException, UnsupportedPosTagStringException {
  String word = tokenAnno.getCoveredText();
  String lemma = tokenAnno.getLemma().getValue();
  String pos = tokenAnno.getPos().getPosValue();
  
  // We rely on the fact the NamedEntity enum values have the same names as the ones
  // specified in the DKPro mapping (e.g. PERSON, ORGANIZATION)
  eu.excitementproject.eop.common.representation.parse.representation.basic.NamedEntity namedEntity=null;
  List<NamedEntity> namedEntities = JCasUtil.selectCovered(NamedEntity.class, tokenAnno);
  switch (namedEntities.size()) {
  case 0: break; // if no NER - ignore and move on
  case 1: namedEntity = eu.excitementproject.eop.common.representation.parse.representation.basic.NamedEntity.valueOf(namedEntities.get(0).getValue());
      break;
  default: throw new CasTreeConverterException(String.format("Got %d NamedEntity annotations for token %s", namedEntities.size(), tokenAnno));
  }
      
  return new DefaultNodeInfo(word, lemma, serial, namedEntity, new DefaultSyntacticInfo(new PennPartOfSpeech(pos)));
}

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.stanfordnlp-gpl

public static CoreLabel tokenToWord(Token aToken)
{
  CoreLabel t = new CoreLabel();
  
  t.setOriginalText(aToken.getCoveredText());
  t.setWord(aToken.getText());
  t.setBeginPosition(aToken.getBegin());
  t.setEndPosition(aToken.getEnd());
  
  if (aToken.getLemma() != null) {
    t.setLemma(aToken.getLemma().getValue());
  }
  else {
    t.setLemma(aToken.getText());
  }
  
  if (aToken.getPos() != null) {
    t.setTag(aToken.getPos().getPosValue());
  }
  
  return t;
}

相关文章