本文整理汇总了Java中net.sf.extjwnl.data.Synset类的典型用法代码示例。如果您正苦于以下问题:Java Synset类的具体用法?Java Synset怎么用?Java Synset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Synset类属于net.sf.extjwnl.data包,在下文中一共展示了Synset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDerivedAdjective
import net.sf.extjwnl.data.Synset; //导入依赖的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;
}
示例2: getSuperSenses
import net.sf.extjwnl.data.Synset; //导入依赖的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();
}
}
示例3: getBestSuperSense
import net.sf.extjwnl.data.Synset; //导入依赖的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()));
}
}
}
示例4: getAlternativeWords
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
/**
* Gets the alternative words from the dictionary.
*
* @param word
* the word
* @return the alternative words (non null and always contains the word itself)
*/
private Stream<String> getAlternativeWords(Word word) {
IndexWord indexWord = null;
try {
indexWord = dictionary.lookupIndexWord(word.getPos(), word.getLemma());
} catch (final Exception e) {
getMonitor().debug("Unable to find word in wordnet, defaulting to lemma form", e);
}
if (indexWord == null) {
return Stream.of(word.getLemma());
}
Set<String> set = new HashSet<String>();
set.add(word.getLemma());
for (Synset synset : indexWord.getSenses()) {
for (net.sf.extjwnl.data.Word w : synset.getWords()) {
set.add(w.getLemma());
}
}
return set.stream();
}
示例5: getParents
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
public List<ISense> getParents(int depth) throws LinguisticOracleException {
List<ISense> out = new ArrayList<>();
try {
PointerTargetTree hypernyms = PointerUtils.getHypernymTree(synset, depth);
for (Iterator itr = hypernyms.toList().iterator(); itr.hasNext(); ) {
if (itr.hasNext()) {
for (Object o : ((PointerTargetNodeList) itr.next())) {
Synset t = ((PointerTargetNode) o).getSynset();
if (!synset.equals(t)) {
out.add(new WordNetSense(t));
}
}
}
}
} catch (JWNLException e) {
throw new LinguisticOracleException(e.getClass().getSimpleName() + ": " + e.getMessage(), e);
}
return out;
}
示例6: getChildren
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
public List<ISense> getChildren(int depth) throws LinguisticOracleException {
List<ISense> out = new ArrayList<>();
try {
PointerTargetTree hypernyms = PointerUtils.getHyponymTree(synset, depth);
for (Iterator itr = hypernyms.toList().iterator(); itr.hasNext(); ) {
if (itr.hasNext()) {
for (Object o : ((PointerTargetNodeList) itr.next())) {
Synset t = ((PointerTargetNode) o).getSynset();
if (!synset.equals(t)) {
out.add(new WordNetSense(t));
}
}
}
}
} catch (JWNLException e) {
throw new LinguisticOracleException(e.getClass().getSimpleName() + ": " + e.getMessage(), e);
}
return out;
}
示例7: getSynonyms
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
public List<String> getSynonyms(String lemma) {
HashSet<String> words = new HashSet<String>();
try {
IndexWord lemmaIndex = dictionary.lookupIndexWord(POS.VERB, lemma);
if (lemmaIndex != null) {
List<Synset> synsets = lemmaIndex.getSenses();
for (Synset synset : synsets) {
words.add(synset.getWords().get(0).getLemma());
}
}
} catch (JWNLException e) {
e.printStackTrace();
}
return Lists.newArrayList(words);
}
示例8: Relationship
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
protected Relationship(PointerType type, PointerTargetNodeList nodes, Synset sourceSynset, Synset targetSynset) {
if (null == type) {
throw new IllegalArgumentException("Type must be not null");
}
this.type = type;
if (null == nodes) {
throw new IllegalArgumentException("Nodes must be not null");
}
this.nodes = nodes;
if (null == sourceSynset) {
throw new IllegalArgumentException("Source synset must be not null");
}
this.sourceSynset = sourceSynset;
if (null == targetSynset) {
throw new IllegalArgumentException("Target synset must be not null");
}
this.targetSynset = targetSynset;
}
示例9: findAsymmetricRelationships
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
/**
* Finds the asymmetric relationship(s) between two words. A relationship is
* asymmetric if its type is asymmetric (i.e. it's not its own inverse).
*
* @param sourceSynset source synset
* @param targetSynset target synset
* @param type pointer type
* @param depth depth
* @return all relationships of type <var>type</var> between <var>sourceSynset</var> and <var>targetSynset</var>
* @throws CloneNotSupportedException CloneNotSupportedException
*/
private static RelationshipList findAsymmetricRelationships(
Synset sourceSynset, Synset targetSynset, PointerType type, int depth) throws CloneNotSupportedException, JWNLException {
// We run the reversal function on the trees to get linear (non-branching)
// paths from the source word to its deepest ancestor (i.e. if there are
// multiple relations from a single word anywhere in the path, the reversal
// function will break them down into multiple, linear paths).
List<PointerTargetNodeList> sourceRelations = new PointerTargetTree(
sourceSynset, PointerUtils.makePointerTargetTreeList(sourceSynset, type, depth)).reverse();
List<PointerTargetNodeList> targetRelations = new PointerTargetTree(
targetSynset, PointerUtils.makePointerTargetTreeList(targetSynset, type, depth)).reverse();
RelationshipList relationships = new RelationshipList();
// Do an exhaustive search for relationships
for (PointerTargetNodeList sourceRelation : sourceRelations) {
for (PointerTargetNodeList targetRelation : targetRelations) {
Relationship relationship = findAsymmetricRelationship(
sourceRelation, targetRelation, type, sourceSynset, targetSynset);
if (relationship != null) {
relationships.add(relationship);
}
}
}
return relationships;
}
示例10: findSymmetricRelationships
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
/**
* A symmetric relationship is one whose type is symmetric (i.e. is it's own inverse).
*
* @param type pointer type
* @param sourceSynset source synset
* @param targetSynset target synset
* @param depth depth
* @return list of symmetric relationships between source and target
*/
private static RelationshipList findSymmetricRelationships(
final Synset sourceSynset, final Synset targetSynset, PointerType type, int depth) throws JWNLException {
PointerTargetTree tree = new PointerTargetTree(
sourceSynset, PointerUtils.makePointerTargetTreeList(sourceSynset, type, null, depth, false));
PointerTargetTreeNodeList.Operation opr = new PointerTargetTreeNodeList.Operation() {
public PointerTargetTreeNode execute(PointerTargetTreeNode testNode) {
if (targetSynset.equals(testNode.getSynset())) {
return testNode;
}
return null;
}
};
List l = tree.getAllMatches(opr);
RelationshipList list = new RelationshipList();
for (Object aL : l) {
PointerTargetNodeList nodes = findSymmetricRelationship((PointerTargetTreeNode) aL, type);
list.add(new SymmetricRelationship(type, nodes, sourceSynset, targetSynset));
}
return list;
}
示例11: testReverse
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
@Test
public void testReverse() throws JWNLException, CloneNotSupportedException {
dictionary.edit();
Synset s1 = dictionary.createSynset(POS.NOUN);
Synset s2 = dictionary.createSynset(POS.NOUN);
SymmetricRelationship r =
new SymmetricRelationship(PointerType.HYPERNYM,
new PointerTargetNodeList(Arrays.asList(
new PointerTargetNode(s1),
new PointerTargetNode(s2)
)),
s1, s2);
Relationship rev = r.reverse();
Assert.assertEquals(2, rev.getSize());
Assert.assertEquals(2, rev.getNodeList().size());
Assert.assertEquals(PointerType.HYPONYM, rev.getNodeList().get(0).getType());
Assert.assertEquals(PointerType.HYPONYM, rev.getNodeList().get(1).getType());
Assert.assertEquals(s2, rev.getNodeList().get(0).getSynset());
Assert.assertEquals(s1, rev.getNodeList().get(1).getSynset());
}
示例12: testGetShallowest
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
@Test
public void testGetShallowest() throws JWNLException {
RelationshipList l = new RelationshipList();
Assert.assertNull(l.getShallowest());
Assert.assertNull(l.getDeepest());
Relationship r = new SymmetricRelationship(PointerType.ANTONYM,
new PointerTargetNodeList(Arrays.asList(new PointerTargetNode(new Synset(null, POS.NOUN)))),
new Synset(null, POS.NOUN), new Synset(null, POS.NOUN));
l.add(r);
Assert.assertEquals(r, l.getDeepest());
Assert.assertEquals(r, l.getShallowest());
Relationship rr = new SymmetricRelationship(PointerType.ANTONYM,
new PointerTargetNodeList(),
new Synset(null, POS.NOUN), new Synset(null, POS.NOUN));
l.add(rr);
Assert.assertEquals(r, l.getDeepest());
Assert.assertEquals(rr, l.getShallowest());
}
示例13: testGetDeepest
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
@Test
public void testGetDeepest() throws JWNLException {
RelationshipList l = new RelationshipList();
Assert.assertNull(l.getShallowest());
Assert.assertNull(l.getDeepest());
Relationship r = new SymmetricRelationship(PointerType.ANTONYM,
new PointerTargetNodeList(),
new Synset(null, POS.NOUN), new Synset(null, POS.NOUN));
l.add(r);
Assert.assertEquals(r, l.getDeepest());
Assert.assertEquals(r, l.getShallowest());
Relationship rr = new SymmetricRelationship(PointerType.ANTONYM,
new PointerTargetNodeList(Arrays.asList(new PointerTargetNode(new Synset(null, POS.NOUN)))),
new Synset(null, POS.NOUN), new Synset(null, POS.NOUN));
l.add(rr);
Assert.assertEquals(rr, l.getDeepest());
Assert.assertEquals(r, l.getShallowest());
}
示例14: testGetRelativeTargetDepth
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
@Test
public void testGetRelativeTargetDepth() throws JWNLException {
dictionary.edit();
Synset s1 = dictionary.createSynset(POS.NOUN);
Synset s2 = dictionary.createSynset(POS.NOUN);
Synset s3 = dictionary.createSynset(POS.NOUN);
AsymmetricRelationship r =
new AsymmetricRelationship(PointerType.HYPERNYM, new PointerTargetNodeList(
Arrays.asList(
new PointerTargetNode(s1),
new PointerTargetNode(s2),
new PointerTargetNode(s3)
)
), 1, s1, s3);
Assert.assertEquals(0, r.getRelativeTargetDepth());
}
示例15: testReverse
import net.sf.extjwnl.data.Synset; //导入依赖的package包/类
@Test
public void testReverse() throws JWNLException, CloneNotSupportedException {
dictionary.edit();
Synset s1 = dictionary.createSynset(POS.NOUN);
Synset s2 = dictionary.createSynset(POS.NOUN);
Synset s3 = dictionary.createSynset(POS.NOUN);
AsymmetricRelationship r =
new AsymmetricRelationship(PointerType.HYPERNYM,
new PointerTargetNodeList(Arrays.asList(
new PointerTargetNode(s1, PointerType.HYPERNYM),
new PointerTargetNode(s2, PointerType.HYPERNYM),
new PointerTargetNode(s3, PointerType.HYPONYM)
)),
1,
s1, s2);
Relationship rev = r.reverse();
Assert.assertEquals(3, rev.getSize());
Assert.assertEquals(3, rev.getNodeList().size());
Assert.assertEquals(PointerType.HYPONYM, rev.getNodeList().get(0).getType());
Assert.assertEquals(PointerType.HYPERNYM, rev.getNodeList().get(1).getType());
Assert.assertEquals(PointerType.HYPONYM, rev.getNodeList().get(2).getType());
}