Exemplo n.º 1
0
 private void combiningNP(Map<String, Rules> rl, Map<String, RuleSet> ruleset, int i) {
   RuleSet rs;
   String rkey;
   int order1, order2;
   Rules rule;
   List<RuleData> ls;
   String keys[] = {
     "NNNP", "VBNP", "JJNP", "NNCP", "VBCP", "JJCP",
   }; // noun, adj, vb in noun phrase
   for (String s : rl.keySet()) {
     rule = rl.get(s);
     rule.initMap();
     // process NP chunk
     // cases to considered: PRO-TG (PRO)*
     // TG prep1 PRO1 (prep2 PRO2)*
     for (String subkey : keys) {
       ls = rule.getEvalRules(subkey); // all NP pattern of current trg
       if (ls == null) {
         continue;
       }
       rkey = s + i + subkey; // trg + type + pos(first two letters) + chunk type
       // has NP patterns
       rs = new RuleSet();
       order1 = 0;
       order2 = 0;
       for (RuleData dt : ls) {
         if (dt.in_chunk) { // in chunk case
           rs.in_chunk = true;
           rs.inchunk_count += dt.count; // count number of inchunk event
           if (!dt.has_cause) { // all event type without theme2/cause
             if (dt.event1) {
               rs.ecount += dt.count;
             } else {
               rs.pcount += dt.count;
             }
           } else if (i == 5 && dt.has_cause) { // theme2 PRO-TG PRO
             rs.t2count += dt.count;
             rs.pcount += dt.count;
             rs.dist2 = Math.max(rs.dist2, dt.dist2);
           } else if (i > 5 && dt.theme_pos && dt.has_cause) { // has cause
             rs.pcause += dt.count; // assume only pro is cause : PRO - TG Theme (Pro/Evt)
             if (dt.event1) {
               rs.ecount += dt.count;
             } else {
               rs.pcount += dt.count;
             }
             rs.dist1 = Math.max(rs.dist1, dt.dist1);
           }
         } else if (dt.theme_pos) { // for all POS : TG - prep - PRO
           if ((dt.POS.startsWith("NN") && !dt.prep1.isEmpty())
               || !dt.POS.startsWith("NN")) { // (NN && prep) or (VB/JJ)
             if (!dt.has_cause) { // all event type, no theme2 / cause
               if (i <= 5) {
                 rs.pcount += dt.count;
               } else {
                 if (dt.event1) {
                   rs.ecount += dt.count;
                 } else {
                   rs.pcount += dt.count;
                 }
               }
               rs.dist1 = Math.max(rs.dist1, dt.dist1);
             } else if (dt.cause_pos
                 && !dt.prep2.isEmpty()
                 && dt.POS.startsWith("NN")) { // TG-prep1-PRO1-prep2-PRO2 ; only NNx
               if (i == 5) {
                 rs.t2count += dt.count;
                 rs.pcount += dt.count;
               } else {
                 if (dt.event1) {
                   rs.ecount += dt.count;
                 } else {
                   rs.pcount += dt.count;
                 }
                 if (dt.event2) {
                   rs.ecause += dt.count;
                 } else {
                   rs.pcause += dt.count;
                 }
               }
               rs.dist1 = Math.max(rs.dist1, dt.dist1);
               rs.dist2 = Math.max(rs.dist2, dt.dist2);
             }
           }
         } else if (i == 5
             && !dt.theme_pos
             && ((dt.has_cause && dt.cause_pos)
                 || !dt.POS.startsWith("NN"))) { // Binding: PRO1 - TG - PRO2
           rs.in_front += dt.count;
           if (!dt.prep2.isEmpty()) {
             rs.prep_2.add(dt.prep2);
           }
           if (!dt.prep1.isEmpty()) {
             rs.prep_1.add(dt.prep1);
           }
           rs.dist1 = Math.max(rs.dist1, dt.dist1);
           rs.dist2 = Math.max(rs.dist2, dt.dist2);
           rs.pcount += dt.count;
           rs.dist2 = Math.max(rs.dist2, dt.dist2);
         }
       }
       rs.detected = getCountDetectedTG(s, subkey);
       if (order2 > order1) {
         rs.order = false;
       }
       if (rs.getFreq() >= 2) {
         ruleset.put(rkey, rs);
       }
     }
   }
 }
Exemplo n.º 2
0
 private void combiningVP(Map<String, Rules> rl, Map<String, RuleSet> ruleset, int i) {
   RuleSet rs;
   String rkey;
   int order1;
   Rules rule;
   List<RuleData> ls;
   String keys[] = {"VBVP", "JJVP"}; // noun, adj, vb in noun phrase
   for (String s : rl.keySet()) {
     rule = rl.get(s);
     rule.initMap();
     // ** VP JJ
     for (String subkey : keys) {
       ls = rule.getEvalRules(subkey); // all NP pattern of current trg
       if (ls == null) {
         continue;
       }
       rkey = s + i + subkey;
       rs = new RuleSet();
       order1 = 0;
       for (RuleData dt : ls) {
         if (dt.count < 2 && i < 5) {
           // continue;
         }
         if (!dt.has_cause) {
           if (i <= 5) {
             rs.pcount += dt.count;
           } else {
             if (dt.event1) {
               rs.ecount += dt.count;
             } else {
               rs.pcount += dt.count;
             }
           }
         } else { // has theme2/cause
           if (i == 5) {
             rs.t2count += dt.count;
             rs.pcount += dt.count;
           } else {
             if (dt.event1) {
               rs.ecount += dt.count;
             } else {
               rs.pcount += dt.count;
             }
             if (dt.event2) {
               rs.ecause += dt.count;
             } else {
               rs.pcause += dt.count;
             }
           }
         }
         if (dt.verb_type == 1 && dt.POS.equals("VBN") && dt.theme_pos) { //
           order1 += dt.count;
         } else if (dt.verb_type == 1 && dt.POS.equals("VBN") && !dt.theme_pos) {
           order1 -= dt.count;
         }
         rs.dist1 = Math.max(rs.dist1, dt.dist1);
         rs.dist2 = Math.max(rs.dist2, dt.dist2);
       }
       rs.detected = getCountDetectedTG(s, subkey);
       if (order1 > 0) {
         rs.order = false;
       }
       if (rs.getFreq() >= 2) {
         ruleset.put(rkey, rs);
       }
     }
   }
 }