1
package com.novamente.nlgen.unary;
2
import java.math.BigInteger;
5
import org.hibernate.SQLQuery;
7
import com.novamente.nlgen.db.*;
8
public class UnaryPatternExtractor {
10
public List<UnaryRelationPattern> extractUnaryRelations(){
11
List<UnaryRelationPattern> patterns=new LinkedList<UnaryRelationPattern>();
12
dao=new BaseHibernateDAO();
13
String sql="SELECT distinct group_concat(label order by label),count(*)" +
14
" FROM `nlgen`.`relation` where type=0 group by word1_id,sentence_id;";
15
SQLQuery query=dao.getSession().createSQLQuery(sql);
16
List result=query.list();
18
for(Object obj:result){
20
UnaryRelationPattern pattern=new UnaryRelationPattern();
21
pattern.setPattern((String)items[0]);
22
pattern.setExampleCount(((BigInteger)items[1]).intValue());
23
patterns.add(pattern);
28
public void findExamples(String example){
29
dao=new BaseHibernateDAO();
30
String sql="SELECT word1_id,sentence_id" +
31
" FROM `nlgen`.`patterns` where pattern='"
33
SQLQuery query=dao.getSession().createSQLQuery(sql);
34
List results=query.list();
39
ProcessedSentence sentence;
40
for(Object obj:results){
42
word_id=(Integer)row[0];
43
sentence_id=(Integer)row[1];
44
word=(SentenceWord)dao.load(SentenceWord.class, word_id);
45
sentence=(ProcessedSentence)dao.load(ProcessedSentence.class, sentence_id);
46
System.out.println(sentence.getInfo().getSentence());
47
System.out.println(word.getWord());
50
public static void main(String[] args){
51
UnaryPatternExtractor upe=new UnaryPatternExtractor();
52
List<UnaryRelationPattern> patterns=upe.extractUnaryRelations();
53
for(UnaryRelationPattern pattern:patterns){
54
System.out.println(pattern);
55
//upe.findExamples(pattern.getPattern());
57
//upe.findExamples("definite,singular");