|
wordnet pojos sample code
|
|||
|
Sample code
or How no (or very little) SQL is needed
or How Hibernate takes care of (nearly) everything
Get Hibernate Session Factory
SessionFactoryUtil.sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Get Hibernate Session
Session session = sessionFactory.openSession();
Get WordNet entity
final Query q = session.createQuery("from Word where lemma = :lemma");
q.setString("lemma", "horse");
final Iterator rs = q.iterate();
while (rs.hasNext())
{
final Word w = (Word) rs.next();
...
}
or (another query)
final Query q = session.createQuery("from Word where lemma like :pattern");
q.setString("pattern", "%horse%");
...
Get entity through identifier
Word w = (Word) session.get(Word.class, new Integer(65264));
Process Word senses and synsets
Word w=...
final Set<Sense> ss = w.getSenses();
for (final Sense s : ss)
{
final Synset sy = s.getSynset();
...
}
Process linked synsets
final Synset sy = s.getSynset(); System.out.println(Utils.synset2String(sy)); // AS SOURCE OF RELATION // semantic relations final Set<Semlink> sls1 = sy.getSemlinksForSynset1id(); for (final Semlink sl1 : sls1) System.out.println(Utils.semLink2String(sl1, true)); // lexical relations final Set<Lexlink> lls1 = sy.getLexlinksForSynset1id(); for (final Lexlink ll1 : lls1) System.out.println(Utils.lexLink2String(ll1, true)); // AS TARGET OF RELATION // semantic relations final Set<Semlink> sls2 = sy.getSemlinksForSynset2id(); for (final Semlink sl2 : sls2) System.out.println(Utils.semLink2String(sl2, false)); // lexical relations final Set<Lexlink> lls2 = sy.getLexlinksForSynset2id(); for (final Lexlink ll2 : lls2) System.out.println(Utils.lexLink2String(ll2, false));
Process synset
Synset sy=...
int id = sy.getSynsetid();
String pos = sy.getPos();
String lex = sy.getLexdomain().getLexdomainname();
String def = sy.getDefinition();
for (final Sense s : sy.getSenses())
{
String lemma = s.getWord().getLemma();
...
}
Process semantic link
final Semlink sl = ... final String type = sl.getLinktype().getLink(); final Synset src = sl.getSynsetBySynset1id(); final Synset dest = sl.getSynsetBySynset2id();
Process lexical link
final Lexlink ll = ... final String type = ll.getLinktype().getLink(); final Word srcw = ll.getWordByWord1id(); final Word destw = ll.getWordByWord2id(); final Synset srcsy = ll.getSynsetBySynset1id(); final Synset destsy = ll.getSynsetBySynset2id();