/** * watch out for "internodes glabrous or midstem ones slightly scabrous ." * * @param sentid * @param sent * @return */ protected String doSimple(String source, String sent) { Pattern simplep = Pattern.compile(StateCollector.simple); Matcher m = simplep.matcher(sent); if (m.find()) { String seg = sent.substring(m.start(), m.end()); System.out.println("\t" + seg); String t1 = normalize(m.group(1)); String t2 = normalize(m.group(2)); if (isValidStateString(t2) && isValidStateString(t1)) { /*TODO move this checkpoint to function group*/ ArrayList<String> list = new ArrayList<String>(); list.add(t1); System.out.print("[" + t1 + "] "); String[] t2s = t2.split("\\b(to|or)\\b"); for (int i = 0; i < t2s.length; i++) { list.add(normalize(t2s[i])); System.out.print("[" + t2s[i] + "] "); } for (int i = 0; i < list.size(); i++) { for (int j = i + 1; j < list.size(); j++) { int score = i == 0 ? -1 : 1; // absent or erect State s1 = statematrix.getStateByName(list.get(i)); State s2 = statematrix.getStateByName(list.get(j)); s1 = s1 == null ? new State(list.get(i)) : s1; s2 = s2 == null ? new State(list.get(j)) : s2; statematrix.addPair(s1, s2, score, source); // statematrix.addPair(new State(list.get(i)), new State(list.get(j)), score); } } System.out.println(" are in the same group [simple] in [" + sent + "]\n"); } sent = sent.replaceFirst(StateCollector.simple, ""); } return sent; }
protected String doList(String source, String sent) { Pattern listp = Pattern.compile(StateCollector.list); Matcher m = listp.matcher(sent); if (m.find()) { String seg = sent.substring(m.start(), m.end()); System.out.println("\t" + seg); String t1 = m.group(1); String t2 = m.group(2); if (isValidStateString(t2) && isValidStateString(t1)) { String[] terms = t1.split("\\s*,\\s*"); List<String> list = Arrays.asList(terms); ArrayList<String> alist = new ArrayList<String>(list); alist.add(t2); for (int i = 0; i < alist.size(); i++) { alist.set(i, normalize((String) alist.get(i))); } System.out.println(t1 + " and " + t2 + " are in the same group [list] in [" + sent + "]\n"); for (int i = 0; i < alist.size(); i++) { for (int j = i + 1; j < alist.size(); j++) { int score = i == 0 ? -1 : 1; // absent or erect State s1 = statematrix.getStateByName(alist.get(i)); State s2 = statematrix.getStateByName(alist.get(j)); s1 = s1 == null ? new State(alist.get(i)) : s1; s2 = s2 == null ? new State(alist.get(j)) : s2; statematrix.addPair(s1, s2, score, source); // statematrix.addPair(new State(alist.get(i)), new State(alist.get(j)), score); } } } sent = sent.replaceFirst(StateCollector.list, ""); } return sent; }