package ever.pipeline; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.regex.Pattern; import ever.workflowRepresentation.WorkflowElement; /** * This class wrapps all the informations about a sentence together * @author Pol Schumacher, Wirtschaftsinformatik, Institut fuer Informatik, Goethe Universitaet Frankfurt * */ public class Sentence implements Serializable{ /** * */ private static final long serialVersionUID = 7; /** * The raw string of the sentence */ private String raw; /** * A list of case frames */ private ArrayList caseFrameList; /** * A list of clauses. A clause is the result of the parsing and a part of speech tagging */ private ArrayList clauseList; /** * This list contains related workflow elements. They are used to be able to track the origin * of an element. */ private ArrayList relWfElements; public Sentence(String caseFrame, String clause) { relWfElements = new ArrayList(); clauseList = new ArrayList(); caseFrameList = new ArrayList(); addCaseFrame(caseFrame); addSegementInfo(clause); } /** * Parse case frame string and create case frame object for further processing */ public void addCaseFrame(String caseFrame) { Scanner sc = new Scanner(caseFrame); sc.useDelimiter("-----------------------------------------------"); sc.next(); while (sc.hasNext()) { CaseFrame c = new CaseFrame(sc.next()); caseFrameList.add(c); } } /** * parse segements of the sentence constructed by ./nlp -seg */ public void addSegementInfo(String in) { raw=(String) in.subSequence(0, in.indexOf("\n")); raw=raw.toLowerCase().trim(); Scanner sc = new Scanner(in); sc.useDelimiter(Pattern.compile("^$", Pattern.MULTILINE)); while (sc.hasNext()) { String cl = sc.next(); cl.trim(); if (cl.equals("\n")) continue; cl = cl.replaceFirst(".+(\\. )", ""); cl = cl.replaceAll("(PreProc : ).+( getCaseFrames() { return caseFrameList; } /** * Returns the raw sentence * @return */ public String getRaw() { return raw; } /** * returns related elements of this sentence * @return */ public ArrayList getRelatedElem() { return relWfElements; } /** * Returns the position of a related workflow element * @param elem * @return */ public int getPosOfRelated(WorkflowElement elem) { return relWfElements.indexOf(elem); } /** * Returns the clause list * @return */ public ArrayList getClauseList() { return clauseList; } /** * Sets clause list * @param clauseList */ public void setClauseList(ArrayList clauseList) { this.clauseList = clauseList; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((raw == null) ? 0 : raw.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Sentence other = (Sentence) obj; if (!raw.equals(other.raw)) return false; return true; } }