本文整理汇总了Java中net.sf.extjwnl.data.POS类的典型用法代码示例。如果您正苦于以下问题:Java POS类的具体用法?Java POS怎么用?Java POS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
POS类属于net.sf.extjwnl.data包,在下文中一共展示了POS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doProcess
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
@Override
protected void doProcess(JCas jCas) throws AnalysisEngineProcessException {
for (WordToken t : JCasUtil.select(jCas, WordToken.class)) {
if (t.getLemmas() == null || t.getLemmas().size() > 0) {
String text = t.getCoveredText();
POS pos = WordNetUtils.toPos(t.getPartOfSpeech());
if (pos != null) {
Optional<IndexWord> lookupWord = wordnet.lookupWord(pos, text);
if (lookupWord.isPresent()) {
t.setLemmas(new FSArray(jCas, 1));
WordLemma wordLemma = new WordLemma(jCas);
wordLemma.setLemmaForm(lookupWord.get().getLemma());
t.setLemmas(0, wordLemma);
}
}
}
}
}
示例2: getDerivedAdjective
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
/**
* Returns the derived adjective with the same word form for the most common
* sense of the given noun if exists.
*
* @param noun
* the noun
*/
public String getDerivedAdjective(String noun) {
try {
IndexWord nounIW = dict.lookupIndexWord(POS.NOUN, noun);
List<Synset> senses = nounIW.getSenses();
Synset mainSense = senses.get(0);
List<Pointer> pointers = mainSense.getPointers(PointerType.DERIVATION);
for (Pointer pointer : pointers) {
Synset derivedSynset = pointer.getTargetSynset();
if (derivedSynset.getPOS() == POS.ADJECTIVE) {
// return derivedSynset.getWords().get(0).getLemma();
}
if (derivedSynset.getPOS() == POS.VERB) {
System.out.println(derivedSynset);
}
}
} catch (JWNLException e) {
e.printStackTrace();
}
return null;
}
示例3: getSuperSenses
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
/**
* Gets the super senses of a word.
*
* The supersense is the original 'sense file' in which word was defined.
*
* @param pos
* the pos
* @param word
* the word
* @return the super senses
*/
public Stream<String> getSuperSenses(POS pos, String word) {
final Optional<IndexWord> indexWord = lookupWord(pos, word);
if (!indexWord.isPresent()) {
return Stream.empty();
} else {
// NOTE: This was stream but it WordNet getSenses() somehow seems incompatible with
// streams
final List<Synset> senses = indexWord.get().getSenses();
final Set<String> set = new HashSet<>();
for (final Synset s : senses) {
set.add(stripPOSFromSupersense(s.getLexFileName()));
}
return set.stream();
}
}
示例4: getBestSuperSense
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
/**
* Gets the best super sense for a word.
*
* @param pos
* the pos
* @param word
* the word
* @return the best super sense
*/
public Optional<String> getBestSuperSense(POS pos, String word) {
final Optional<IndexWord> indexWord = lookupWord(pos, word);
if (!indexWord.isPresent()) {
return Optional.empty();
} else {
final List<Synset> senses = indexWord.get().getSenses();
if (senses.isEmpty()) {
return Optional.empty();
} else {
// At this stage we could do something clever, look at the gloss to see is there are
// word overlaps
// but we opt for a more predicatable concept of selecting the most commonly used
// meaning sense.
return Optional.of(stripPOSFromSupersense(senses.get(0).getLexFileName()));
}
}
}
示例5: toPos
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
/**
* Convert a string (Penntree bank / simple word) to a Part of speech type.
*
* @param pos
* the pos
* @return the pos
*/
public static POS toPos(String pos) {
final String lc = pos.toLowerCase();
POS ret = null;
if (lc.startsWith("n")) {
ret = POS.NOUN;
} else if (lc.startsWith("v")) {
ret = POS.VERB;
} else if (lc.startsWith("r") || lc.startsWith("adv")) {
ret = POS.ADVERB;
} else if (lc.startsWith("j") || lc.startsWith("adj")) {
ret = POS.ADJECTIVE;
}
return ret;
}
示例6: doProcess
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
@Override
protected void doProcess(JCas jCas) throws AnalysisEngineProcessException {
for (final WordToken t : JCasUtil.select(jCas, WordToken.class)) {
if (t.getLemmas() == null || t.getLemmas().size() == 0) {
final String text = t.getCoveredText();
final POS pos = WordNetUtils.toPos(t.getPartOfSpeech());
if (pos != null) {
final Optional<IndexWord> lookupWord = wordnet.lookupWord(pos, text);
if (lookupWord.isPresent()) {
t.setLemmas(new FSArray(jCas, 1));
final WordLemma wordLemma = new WordLemma(jCas);
wordLemma.setLemmaForm(lookupWord.get().getLemma());
t.setLemmas(0, wordLemma);
}
}
}
}
}
示例7: extractInteractionWords
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
/**
* Extract interaction words from the clustered patterns.
*
* @param clusters
* the clusters
* @param minWordOccurances
* @return the stream of interaction words
*/
private Stream<InteractionWord> extractInteractionWords(List<ClusteredPatterns> clusters) {
return clusters.stream().flatMap(cluster -> {
// TODO: Should we use token or terms here?
final Map<Word, Long> wordCount = cluster.getPatterns().stream()
.flatMap(p -> p.getTokens().stream())
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
final Set<RelationPair> relationPairs = cluster.getPairs();
return wordCount.entrySet().stream()
.filter(e -> e.getValue() >= minWordOccurances)
.map(e -> new InteractionWord(e.getKey(), relationPairs));
}).filter(w -> w.getWord().getPos() == POS.NOUN || w.getWord().getPos() == POS.VERB).distinct();
// We need to map verbs and nouns to lemmas (which might have already been done)
// Then map verbs to nouns and vice versa.
}
示例8: test
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
@Test
public void test() {
final PatternReference p = new PatternReference("id", new Word("a", POS.NOUN), new Word("b", POS.NOUN));
assertEquals("id", p.getId());
assertEquals("a", p.getTokens().get(0).getLemma());
assertEquals(POS.NOUN, p.getTokens().get(0).getPos());
p.setSourceType("st");
p.setTargetType("tt");
assertEquals("tt", p.getTargetType());
assertEquals("st", p.getSourceType());
final PatternReference p2 = new PatternReference("id", new Word("a", POS.NOUN));
final HashSet<Word> tokens = new HashSet<>(Arrays.asList(new Word("a", POS.NOUN), new Word("b", POS.NOUN)));
p.calculateTermFrequency(tokens);
p2.calculateTermFrequency(tokens);
final double similarity = p.calculateSimilarity(p2);
assertEquals(0.5, similarity, 0.1);
}
示例9: testSingle
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
@Test
public void testSingle() {
ClusteredPatterns cp = new ClusteredPatterns();
Word word1 = new Word("lemma1", POS.NOUN);
Word word2 = new Word("lemma2", POS.NOUN);
PatternReference one = new PatternReference("1", Arrays.asList(word1));
PatternReference two = new PatternReference("2", Arrays.asList(word1,
word2));
PatternReference three = new PatternReference("3", Arrays.asList(word2));
Set<Word> set = new HashSet<>(Arrays.asList(word1, word2));
one.calculateTermFrequency(set);
two.calculateTermFrequency(set);
three.calculateTermFrequency(set);
cp.add(one);
assertEquals(1.0, cp.calculateSimilarity(one), 0.001);
assertEquals(0.5, cp.calculateSimilarity(two), 0.001);
assertEquals(0.0, cp.calculateSimilarity(three), 0.001);
}
示例10: testEuqalsAndHashcode
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
@Test
public void testEuqalsAndHashcode() {
final Word w1n = new Word("lemma1", POS.NOUN);
final Word w1n2 = new Word("lemma1", POS.NOUN);
final Word w1v = new Word("lemma1", POS.VERB);
final Word w2n = new Word("lemma2", POS.NOUN);
final Word w2v = new Word("lemma2", POS.VERB);
final Word w3 = new Word("lemma3", null);
final Word w32 = new Word("lemma3", null);
final Word w4 = new Word("lemma4", null);
assertNotEquals(w1n, null);
assertNotEquals(w1n, "lemma");
assertNotEquals(w1n, w1v);
assertNotEquals(w1n, w2v);
assertNotEquals(w1n, w2n);
assertEquals(w1n, w1n2);
assertEquals(w3, w32);
assertNotEquals(w3, w4);
}
示例11: testHashCodeAndEquals
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
@Test
public void testHashCodeAndEquals() {
final Set<RelationPair> set1 = new HashSet<>();
final Word word1 = new Word("lemma1", POS.NOUN);
final Set<RelationPair> set2 = new HashSet<>(Arrays.asList(new RelationPair("s", "t")));
final Word word2 = new Word("lemma2", POS.NOUN);
final InteractionWord iw11 = new InteractionWord(word1, set1);
final InteractionWord iw12 = new InteractionWord(word1, set2);
final InteractionWord iw21 = new InteractionWord(word2, set1);
final InteractionWord iw22 = new InteractionWord(word2, set2);
Assert.assertNotEquals(iw11, iw12);
Assert.assertNotEquals(iw11, iw21);
Assert.assertNotEquals(iw11, iw22);
Assert.assertNotEquals(iw11.hashCode(), iw12.hashCode());
Assert.assertNotEquals(iw11.hashCode(), iw21.hashCode());
Assert.assertNotEquals(iw11.hashCode(), iw22.hashCode());
}
示例12: test
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
@Test
public void test() throws Exception{
File file = new File(getClass().getResource("interactions.csv").toURI());
CsvInteractionReader reader = new CsvInteractionReader(file.getAbsolutePath());
count = 0;
reader.read((i, a) -> {
count++;
assertNotNull(i.getType());
assertNotNull(i.getSubType());
assertNotNull(i.getSource());
assertNotNull(i.getTarget());
assertNotNull(i.getWord());
assertEquals(POS.NOUN, i.getWord().getPos());
assertNotNull(a);
assertFalse(a.isEmpty());
});
assertEquals(new Integer(3), count);
}
示例13: getJwnlPartOfSpeec
import net.sf.extjwnl.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;
}
}
示例14: addToCalculation
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
/**
* Add to the overall calculation
*
* @param pos1
* - first word part of speech
* @param pos2
* - second word part of speech
* @param r
* - relationship between the two
*/
private void addToCalculation(POS pos1, POS pos2, Relationship r) {
int i = pos1.getId() - 1;
int j = pos2.getId() - 1;
int k = PointerType.getAllPointerTypes().indexOf(r.getType());
// Increment the number of calculations done between these pointer types
counts[i][j][k]++;
// Increment the overall depth count
depths[i][j][k] += r.getDepth();
// Increment the overall size count
sizes[i][j][k] += r.getSize();
}
示例15: execute
import net.sf.extjwnl.data.POS; //导入依赖的package包/类
/**
* Execute the task of counting dictionary references
*
* @throws JWNLException
*/
public void execute() throws JWNLException {
IWiktionaryEdition wkt = JWKTL.openEdition(dumpFile);
Dictionary d = Constants.getDictionary();
// Do Noun Calculations
doCalculationsForPOS(wkt, d, POS.NOUN);
// Do Verb Calculations
doCalculationsForPOS(wkt, d, POS.VERB);
// Do Adjective Calculations
doCalculationsForPOS(wkt, d, POS.ADJECTIVE);
// Do Adverb Calculations
doCalculationsForPOS(wkt, d, POS.ADVERB);
// Free up some resources
wkt.close();
}