~nlgen-dev/nlgen/trunk

« back to all changes in this revision

Viewing changes to src/java/com/novamente/nlgen/unary/UnaryPatternExtractor.java

  • Committer: Samir Araujo
  • Date: 2009-10-08 13:08:39 UTC
  • Revision ID: samir.araujo@gmail.com-20091008130839-n5walmp9ntaivtjb
 - Clean up the project, added some info files and prepared it to be used in a easier way

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package com.novamente.nlgen.unary;
2
 
import java.math.BigInteger;
3
 
import java.util.*;
4
 
 
5
 
import org.hibernate.SQLQuery;
6
 
 
7
 
import com.novamente.nlgen.db.*;
8
 
public class UnaryPatternExtractor {
9
 
        BaseHibernateDAO dao;
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();
17
 
                Object[] items;
18
 
                for(Object obj:result){
19
 
                        items=(Object[])obj;
20
 
                        UnaryRelationPattern pattern=new UnaryRelationPattern();
21
 
                        pattern.setPattern((String)items[0]);
22
 
                        pattern.setExampleCount(((BigInteger)items[1]).intValue());
23
 
                        patterns.add(pattern);
24
 
                }
25
 
                dao.closeSession();
26
 
                return patterns;
27
 
        }
28
 
        public void findExamples(String example){
29
 
                dao=new BaseHibernateDAO();
30
 
                String sql="SELECT word1_id,sentence_id" +
31
 
                                " FROM `nlgen`.`patterns` where pattern='"
32
 
                                +example+"';";
33
 
                SQLQuery query=dao.getSession().createSQLQuery(sql);
34
 
                List results=query.list();
35
 
                Object[] row;
36
 
                Integer word_id;
37
 
                Integer sentence_id;
38
 
                SentenceWord word;
39
 
                ProcessedSentence sentence;
40
 
                for(Object obj:results){
41
 
                        row=(Object[])obj;
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());
48
 
                }
49
 
        }
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());
56
 
                }
57
 
                //upe.findExamples("definite,singular");
58
 
        }
59
 
}