public class WNGraph extends Object
A collection of utility methods for applying graph traversals and algorithms onto the HyperGraph representation of WordNet.
Constructor and Description |
---|
WNGraph(org.hypergraphdb.HyperGraph graph) |
Modifier and Type | Method and Description |
---|---|
org.hypergraphdb.HGHandle |
findIsaRoot(org.hypergraphdb.HGHandle synset)
Find the top-level ancestor of node in an IS-A hierarchy.
|
List<org.hypergraphdb.HGHandle> |
findRelated(org.hypergraphdb.HGHandle synset,
Class<? extends SemanticLink> type,
boolean leftToRight) |
org.hypergraphdb.HGHandle |
findWord(String lemma)
Return the
HGHandle of a WordNet Word instance given its lemma. |
List<org.hypergraphdb.HGHandle> |
getAdjSenses(org.hypergraphdb.HGHandle word)
Return all senses of
word when used as an adjective. |
List<org.hypergraphdb.HGHandle> |
getAdverbSenses(org.hypergraphdb.HGHandle word)
Return all senses of
word when used as an adverb. |
org.hypergraphdb.HyperGraph |
getGraph()
Return the underlying HyperGraph instance.
|
long |
getIsaDepth(org.hypergraphdb.HGHandle synset,
org.hypergraphdb.HGHandle root)
Assuming
synset is a descendant of root in an IS-A
hierarchy, finding the distance between them. |
org.hypergraphdb.HGHandle |
getNounIsaRoot()
Retrieve the root of the noun ISA hierarchy.
|
List<org.hypergraphdb.HGHandle> |
getNounSenses(org.hypergraphdb.HGHandle word)
Return all senses of
word when used as a noun. |
org.hypergraphdb.HGHandle |
getSenseById(long id)
Return a WordNet sense by its offset/id in the original WordNet files.
|
List<org.hypergraphdb.HGHandle> |
getSenses(org.hypergraphdb.HGHandle word,
Class<? extends SynsetLink> type)
Retrieve all senses of a particular word if used as a specific part-of-speech.
|
List<org.hypergraphdb.HGHandle> |
getSenses(org.hypergraphdb.HGHandle word,
org.hypergraphdb.HGHandle senseType)
Retrieve all senses of a particular word if used as a specific part-of-speech.
|
org.hypergraphdb.HGHandle |
getSenseType(Pos pos)
Retrieve the sense type (i.e.
|
<T> WNStat<T> |
getStatistic(Class<? extends WNStat<T>> type)
Return the instance of a global WordNet statistic by its type.
|
<T> T |
getStatisticValue(Class<? extends WNStat<T>> type)
Return the value of a global WordNet statistic by its type or null if that statistic
hasn't been calculated yet.
|
org.hypergraphdb.HGHandle |
getVerbIsaRoot()
Return the root verb sense of the IS-A hierarchy.
|
List<org.hypergraphdb.HGHandle> |
getVerbSenses(org.hypergraphdb.HGHandle word)
Return all senses of
word when used as a verb. |
org.hypergraphdb.algorithms.HGALGenerator |
isaRelatedGenerator(boolean returnChildren,
boolean returnParents)
Return a generator for the
Isa semantic relationships. |
org.hypergraphdb.algorithms.HGTraversal |
relatedBreadthFirst(org.hypergraphdb.HGHandle start,
Class<? extends SemanticLink> type,
boolean leftToRight) |
org.hypergraphdb.algorithms.HGTraversal |
relatedDepthFirst(org.hypergraphdb.HGHandle start,
Class<? extends SemanticLink> type,
boolean leftToRight) |
org.hypergraphdb.algorithms.HGALGenerator |
relatedGenerator(Class<? extends SemanticLink> type)
Get a generator for a symmetric semantic relationship (such as the
Similar
relationships between adjective senses. |
org.hypergraphdb.algorithms.HGALGenerator |
relatedGenerator(Class<? extends SemanticLink> type,
boolean leftToRight)
Get an atom adjency generator for a WordNet semantic relationship.
|
public org.hypergraphdb.HyperGraph getGraph()
Return the underlying HyperGraph instance.
public org.hypergraphdb.HGHandle findWord(String lemma)
Return the HGHandle
of a WordNet Word
instance given its lemma.
lemma
- public <T> T getStatisticValue(Class<? extends WNStat<T>> type)
Return the value of a global WordNet statistic by its type or null if that statistic hasn't been calculated yet.
T
- type
- public <T> WNStat<T> getStatistic(Class<? extends WNStat<T>> type)
Return the instance of a global WordNet statistic by its type. A new instance will
be created and added to the HyperGraphDB if it doesn't already exist. Note that
the statistic will NOT automatically calculated. If you have not previously
triggered a calculation of the statistic and want to lazily calculate it as soon
as it is needed, call its isCalculated
to check and trigger the
calculation on the spot.
T
- type
- public org.hypergraphdb.HGHandle findIsaRoot(org.hypergraphdb.HGHandle synset)
Find the top-level ancestor of node in an IS-A hierarchy. Note that this doesn't perform any cycle detection - it could loop forever if the underlying graph structure is not a DAG.
synset
- A sense participating in an IS-A hierarchy.synset
public long getIsaDepth(org.hypergraphdb.HGHandle synset, org.hypergraphdb.HGHandle root)
Assuming synset
is a descendant of root
in an IS-A
hierarchy, finding the distance between them.
In case the method finds out that synset
is not a descendent of
root
, then -1
is returned.
synset
- The descendant.root
- The root.synset
and root
in an IS-A DAG.public org.hypergraphdb.HGHandle getNounIsaRoot()
Retrieve the root of the noun ISA hierarchy. Recent versions of WordNet have the word "entity" mapped in a single synset which is the top-level noun sense.
public org.hypergraphdb.HGHandle getVerbIsaRoot()
Return the root verb sense of the IS-A hierarchy. Unlike nouns, WordNet doesn't define a top-level verb sense (simply because there isn't a good enough candidate in the English vocabulary). However, for computational purposes we can connect all top-level nodes in the verb IS-A DAG to a single root.
This method will return the dummy verb sense that serves as the top-level node. If it hasn't been already create, it will create and connect it to all existing top-level nodes. Which, of course, is somewhat computational intensive.
public org.hypergraphdb.algorithms.HGALGenerator isaRelatedGenerator(boolean returnChildren, boolean returnParents)
Return a generator for the Isa
semantic relationships. The generator
will examine atoms that are related to the current one through Isa
or
one of its derived relationship types (InstanceOf, KindOf).
returnChildren
- Whether to include more specific (i.e. hyponym) concepts
than the current one being examined.returnParents
- Whether to include more general (i.e. hypernym) concepts
than the current one being examined.public org.hypergraphdb.algorithms.HGALGenerator relatedGenerator(Class<? extends SemanticLink> type)
Get a generator for a symmetric semantic relationship (such as the Similar
relationships between adjective senses.
public org.hypergraphdb.algorithms.HGALGenerator relatedGenerator(Class<? extends SemanticLink> type, boolean leftToRight)
Get an atom adjency generator for a WordNet semantic relationship.
type
- One of the SemanticLink
sub-classes.leftToRight
- true
if the second targets of the relationships
should be traversed and false
if the first targets should be
traversed.public org.hypergraphdb.algorithms.HGTraversal relatedDepthFirst(org.hypergraphdb.HGHandle start, Class<? extends SemanticLink> type, boolean leftToRight)
public org.hypergraphdb.algorithms.HGTraversal relatedBreadthFirst(org.hypergraphdb.HGHandle start, Class<? extends SemanticLink> type, boolean leftToRight)
public List<org.hypergraphdb.HGHandle> findRelated(org.hypergraphdb.HGHandle synset, Class<? extends SemanticLink> type, boolean leftToRight)
public org.hypergraphdb.HGHandle getSenseById(long id)
Return a WordNet sense by its offset/id in the original WordNet files. Note that this id is not stable across WordNet versions. However, in general, there is a way to convert ids between consecutive versions so it's relatively safe to use it as an identifier outside HyperGraphDB.
id
- public org.hypergraphdb.HGHandle getSenseType(Pos pos)
Retrieve the sense type (i.e. the concrete SynsetLink
type atom)
for a given part of speech.
pos
- The part of speech.HGHandle
of the type atom representing the sense type.public List<org.hypergraphdb.HGHandle> getSenses(org.hypergraphdb.HGHandle word, org.hypergraphdb.HGHandle senseType)
Retrieve all senses of a particular word if used as a specific part-of-speech.
The part-of-speech is identified by the senseType
parameter.
Alternatively, you can use one of the getTSenses
methods
where T is one of Noun, Verb, Adverb or
Adj.
word
- The word handle.senseType
- The sense type - this corresponds to one of the sub-classes of
the SynsetLink
class.public List<org.hypergraphdb.HGHandle> getSenses(org.hypergraphdb.HGHandle word, Class<? extends SynsetLink> type)
Retrieve all senses of a particular word if used as a specific part-of-speech.
The part-of-speech is identified by the senseType
parameter.
Alternatively, you can use one of the getTSenses
methods
where T is one of Noun, Verb, Adverb or
Adj.
word
- The word handle.senseType
- The sense type - one of the sub-classes of
the SynsetLink
class.public List<org.hypergraphdb.HGHandle> getNounSenses(org.hypergraphdb.HGHandle word)
Return all senses of word
when used as a noun.
public List<org.hypergraphdb.HGHandle> getVerbSenses(org.hypergraphdb.HGHandle word)
Return all senses of word
when used as a verb.
public List<org.hypergraphdb.HGHandle> getAdverbSenses(org.hypergraphdb.HGHandle word)
Return all senses of word
when used as an adverb.
public List<org.hypergraphdb.HGHandle> getAdjSenses(org.hypergraphdb.HGHandle word)
Return all senses of word
when used as an adjective.
Copyright © 2015. All rights reserved.