List of usage examples for org.hibernate Criteria createCriteria
public Criteria createCriteria(String associationPath) throws HibernateException;
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Returns the {@link Sense} instance contained in the database accessed by this {@link Uby} * instance. The returned senses are filtered by the given name of the external system and * external reference./* w w w . j av a 2s .co m*/ * * @param externalSys * the {@link String} representing the name of external system such as: * FrameNet_1.5_eng_lexicalUnit VerbNet_3.1_eng_sense * OmegaWiki_<version>_<language>_synTrans WordNet_3.0_eng_senseKey * Wiktionary_<version>_<language>_sense Wikipedia_<version>_<language>_articleTitle * GermaNet_7.0_deu_lexicalUnit * @param externalRef * the reference string from external system, such as: * <ul> * <li>WordNet: "[POS: noun] house%1:15:00::" - POS and sense key Returns a list of * one sense</li> * <li>VerbNet: "retire_withdraw-82-3" Several UBY senses can have the same original * sense ID</li> * <li>FrameNet: "2676" - lexical unit ID</li> * <li>Wiktionary: "16:0:1" - sense key</li> * <li>Wikipedia: "House" - article title</li> * <li>OW: "303002" - OW SynTrans Id</li> * </ul> * @return a {@link List} of all senses filtered by the given arguments or an empty list if if * one of the given arguments is null or the accessed database does not contain any * senses matching both constraints */ public List<Sense> getSensesByOriginalReference(String externalSys, String externalRef) { Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.createCriteria("monolingualExternalRefs").add(Restrictions.and( Restrictions.eq("externalSystem", externalSys), Restrictions.eq("externalReference", externalRef))); @SuppressWarnings("unchecked") List<Sense> result = criteria.list(); if (result == null) { result = new ArrayList<Sense>(0); } return result; }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Returns the {@link Synset} instance contained in the database accessed by this {@link Uby} * instance./* ww w. jav a2 s . c om*/ * * @param externalSys * the {@link String} representing the name of external system such as: * OmegaWiki_2010-01-03_eng_definedMeaning WordNet_3.0_eng_synsetOffset * GermaNet_7.0_deu_synset * * @param externalRef * the Synset ID used in the external system, * * @returns the {@link Synset} specified by the given arguments */ public Synset getSynsetByOriginalReference(String externalSys, String externalRef) { Criteria criteria = session.createCriteria(Synset.class); criteria = criteria.createCriteria("monolingualExternalRefs").add(Restrictions.and( Restrictions.eq("externalSystem", externalSys), Restrictions.eq("externalReference", externalRef))); return (Synset) criteria.uniqueResult(); }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Returns the {@link Sense} instance contained in the database accessed by this {@link Uby} * instance. The returned senses are filtered by the given name of the external system, external * reference and lexicon.//from w w w . java 2s .c o m * * @return a {@link List} of all senses filtered by the given arguments or an empty list if one * of the given arguments is null or the accessed database does not contain any senses * matching both constraints. **/ public List<Sense> getSensesByOriginalReference(String externalSys, String externalRef, Lexicon lexicon) { Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.createCriteria("monolingualExternalRefs").add(Restrictions.and( Restrictions.eq("externalSystem", externalSys), Restrictions.eq("externalReference", externalRef))); @SuppressWarnings("unchecked") List<Sense> result = criteria.list(); if (result == null) { result = new ArrayList<Sense>(0); } List<Sense> temp = new ArrayList<Sense>(result); for (Sense s : temp) { if (!s.getLexicalEntry().getLexicon().getName().equals(lexicon.getName())) { result.remove(s); } } return result; }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * @param POS// w w w . j a va 2 s . c om * : POS value=comment<br> * a = adj;<br> * n = noun;<br> * r = adv<br> * v = verb<br> * @param SynsetOffset * : offset value of Synset; * @return list of senses belong to the given synset * @Deprecated use {@link #wordNetSenses(String, String)} or * {@link #wordNetSense(String, String)} instead */ @Deprecated public List<Sense> getSensesByWNSynsetId(String POS, String SynsetOffset) throws ClassNotFoundException, SQLException { String refId = "[POS: noun] "; if (POS.equals("a")) { refId = refId.replaceAll("noun", "adjective"); } else if (POS.equals("r")) { refId = refId.replaceAll("noun", "adverb"); } else if (POS.equals("v")) { refId = refId.replaceAll("noun", "verb"); } refId = refId + SynsetOffset; Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.createCriteria("monolingualExternalRefs") .add(Restrictions.sqlRestriction("externalReference='" + refId.trim() + "'")); @SuppressWarnings("unchecked") List<Sense> result = criteria.list(); return result; }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Consumes a synset identifier (in WordNet terminology) and returns a {@link List} of * {@link Sense} instances which are derived from the WordNets synset, specified by the consumed * identifier.//from www . j av a 2 s. c o m * * @param wnSynsetId * string representation of the WordNets synset identifier i.e. "1740-n" * * @return a list of senses derived from the WordNets synset, specified by the consumed * identifier * <p> * This method returns an empty list if the database accessed by this {@link Uby} * instance does not contain senses derived from the specified WordNet synset. * * @deprecated use {@link #wordNetSense(String, String)} and * {@link #wordNetSense(String, String)} instead */ @Deprecated public List<Sense> getSensesByWNSynsetId(String wnSynsetId) { String[] temp = wnSynsetId.split("-"); String refId = "[POS: noun] "; if (temp[1].equals("a")) { refId = refId.replaceAll("noun", "adjective"); } else if (temp[1].equals("r")) { refId = refId.replaceAll("noun", "adverb"); } else if (temp[1].equals("v")) { refId = refId.replaceAll("noun", "verb"); } refId = refId + temp[0]; Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.createCriteria("synset").createCriteria("monolingualExternalRefs") .add(Restrictions.sqlRestriction("externalReference='" + refId.trim() + "'")); @SuppressWarnings("unchecked") List<Sense> result = criteria.list(); return result; }
From source file:de.tudarmstadt.ukp.lmf.api.UbyStatistics.java
License:Apache License
/** * Counts the number of {@link Sense} instances in the {@link Lexicon} * specified by the given name./* w w w . j a v a2 s .c o m*/ * * @param lexiconName * name of the lexicon which senses should be counted * * @return the number of senses in the lexicon or zero, if the * lexicon with the specified name does not exist */ public long countSensesPerLexicon(String lexiconName) { Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.createCriteria("lexicalEntry").createCriteria("lexicon"); criteria = criteria.add(Restrictions.eq("name", lexiconName)); long count = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); return count; }
From source file:de.tudarmstadt.ukp.lmf.api.UbyStatistics.java
License:Apache License
/** * Counts the number of {@link LexicalEntry} instances in the {@link Lexicon} * specified by the given name.// w w w. j a v a2 s . c o m * * @param lexiconName * name of the lexicon which lexical entries should be counted * * @return the number of lexical entries in the lexicon or zero, if the * lexicon with the specified name does not exist */ public long countLexicalEntriesPerLexicon(String lexiconName) { Criteria criteria = session.createCriteria(LexicalEntry.class); criteria = criteria.createCriteria("lexicon"); criteria = criteria.add(Restrictions.eq("name", lexiconName)); long count = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); return count; }
From source file:de.tudarmstadt.ukp.lmf.api.UbyStatistics.java
License:Apache License
/** * Counts the number of {@link SenseRelation} instances within the {@link Lexicon} * specified by the given name.//from w w w. j a va 2 s .c om * * @param lexiconName * name of the lexicon which senses should be counted * * @return the number of sense relations in the lexicon or zero if the * lexicon with the specified name does not exist */ public long countSenseRelationsPerLexicon(String lexiconName) { Criteria criteria = session.createCriteria(SenseRelation.class); criteria = criteria.createCriteria("source"); criteria = criteria.createCriteria("lexicalEntry"); criteria = criteria.createCriteria("lexicon"); criteria = criteria.add(Restrictions.eq("name", lexiconName)); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
From source file:de.tudarmstadt.ukp.lmf.api.UbyStatistics.java
License:Apache License
/** * Counts the number of {@link SenseAxis} instances between two {@link Lexicon} instances * identified by their name. The counted sense axes are filtered by the * specified type.<p>/*w ww. ja va 2s. co m*/ * <b>Important properties of this method:</b> * <ul> * <li>Only alignments between {@link Sense} instances are considered.</li> * <li>The sources of the alignments are not distinguished.</li> * <li>The lexicons are identified by identifier prefixes of the aligned senses.</li> * </ul> * * @param type * Type of sense axes to be considered when counting * * @param lex1Name * The name of the first of two lexicons between which sense axes should be counted * * @param lex2Name * The name of the second of two lexicons between which sense axes should be counted * * @return the number of sense axes between the lexicons filtered by the specified sense axes type. * This method returns zero if a lexicon with the specified name does not exist or one of the * consumed arguments is null. * * @see ESenseAxisType */ public long countSenseAxesPerLexiconPair(ESenseAxisType type, String lex1Name, String lex2Name) { // get prefix for res1Name Criteria c1 = session.createCriteria(Sense.class, "s"); c1 = c1.createCriteria("lexicalEntry"); c1 = c1.createCriteria("lexicon"); c1 = c1.add(Restrictions.eq("name", lex1Name)); c1 = c1.setProjection(Projections.property("s.id")); c1 = c1.setMaxResults(1); String res1 = (String) c1.uniqueResult(); //get prefix for res2Name Criteria c2 = session.createCriteria(Sense.class, "s"); c2 = c2.createCriteria("lexicalEntry"); c2 = c2.createCriteria("lexicon"); c2 = c2.add(Restrictions.eq("name", lex2Name)); c2 = c2.setProjection(Projections.property("s.id")); c2 = c2.setMaxResults(1); String res2 = (String) c2.uniqueResult(); String pref1 = ""; String pref2 = ""; if (res1 != null && res2 != null) { pref1 = res1.split("_")[0]; if (res1.split("_")[1].equals("en") || res1.split("_")[1].equals("de")) { pref1 += "_" + res1.split("_")[1]; } pref2 = res2.split("_")[0]; if (res2.split("_")[1].equals("en") || res2.split("_")[1].equals("de")) { pref2 += "_" + res2.split("_")[1]; } // get alignments with these prefixes Criteria criteria = session.createCriteria(SenseAxis.class); criteria = criteria.add(Restrictions.eq("senseAxisType", type)); criteria = criteria.add(Restrictions.like("senseOne.id", pref1, MatchMode.START)); criteria = criteria.add(Restrictions.like("senseTwo.id", pref2, MatchMode.START)); criteria = criteria.setProjection(Projections.rowCount()); return (Long) criteria.uniqueResult(); } else { return 0L; } }
From source file:de.tudarmstadt.ukp.lmf.api.UbyStatistics.java
License:Apache License
/** * Returns a {@link List} containing all {@link SenseAxis} instances between two {@link Lexicon} instances * identified by their name. The counted sense axes are filtered by the * specified type.<p>//from ww w.ja v a2 s .co m * <b>Important properties of this method:</b> * <ul> * <li>Only alignments between {@link Sense} instances are considered.</li> * <li>The sources of the alignments are not distinguished.</li> * <li>The lexicons are identified by identifier prefixes of the aligned senses.</li> * </ul> * * @param type * Type of sense axes to be returned * * @param lex1Name * The name of the first of two lexicons between which sense axes should be found * @param lex2Name * The name of the second of two lexicons between which sense axes should be found * * @return the list of sense axes between the lexicons filtered by the specified sense axes type. * This method returns an empty list if a lexicon with the specified name does not exist or one of * the consumed arguments is null. * * @see ESenseAxisType */ @SuppressWarnings("unchecked") public List<SenseAxis> getSenseAxesPerLexiconPair(ESenseAxisType type, String lex1Name, String lex2Name) { // get prefix for res1Name Criteria c1 = session.createCriteria(Sense.class, "s"); c1 = c1.createCriteria("lexicalEntry"); c1 = c1.createCriteria("lexicon"); c1 = c1.add(Restrictions.eq("name", lex1Name)); c1 = c1.setProjection(Projections.property("s.id")); c1 = c1.setMaxResults(1); String res1 = (String) c1.uniqueResult(); //get prefix for res2Name Criteria c2 = session.createCriteria(Sense.class, "s"); c2 = c2.createCriteria("lexicalEntry"); c2 = c2.createCriteria("lexicon"); c2 = c2.add(Restrictions.eq("name", lex2Name)); c2 = c2.setProjection(Projections.property("s.id")); c2 = c2.setMaxResults(1); String res2 = (String) c2.uniqueResult(); String pref1 = ""; String pref2 = ""; if (res1 != null && res2 != null) { pref1 = res1.split("_")[0]; if (res1.split("_")[1].equals("en") || res1.split("_")[1].equals("de")) { pref1 += "_" + res1.split("_")[1]; } pref2 = res2.split("_")[0]; if (res2.split("_")[1].equals("en") || res2.split("_")[1].equals("de")) { pref2 += "_" + res2.split("_")[1]; } // get alignments with these prefixes Criteria criteria = session.createCriteria(SenseAxis.class); criteria = criteria.add(Restrictions.eq("senseAxisType", type)); criteria = criteria.add(Restrictions.like("senseOne.id", pref1, MatchMode.START)); criteria = criteria.add(Restrictions.like("senseTwo.id", pref2, MatchMode.START)); return criteria.list(); } else return new ArrayList<SenseAxis>(); }