package ever.pipeline; import java.util.ArrayList; import javax.swing.border.EtchedBorder; import ever.workflowRepresentation.Sequence; import ever.workflowRepresentation.Task; import ever.workflowRepresentation.WorkflowElement; /** * Abstract class for analyzers which process the input or case frame files one by one * @author Pol Schumacher, Wirtschaftsinformatik, Institut fuer Informatik, Goethe Universitaet Frankfurt * */ public abstract class AbstractLocalInputAnalyzer extends Analyzer { @Override public boolean isLocal() { return true; } public int getWfePosition(Sentence s, ArrayList related, Task toAdd, Sequence seq) { // find item with the minimal distance in the sentence int indexT = s.getRaw().indexOf(toAdd.getName()); // set start distance to maximum int minDist = s.getRaw().length(); Task nearest = null; for (WorkflowElement wfe : related) { Task et = (Task) wfe; if(et.getName().equals(toAdd.getName())) { return seq.indexOf(et); } // if (et.equals(t)) // continue; // Compare name and find position based on the position in // the raw text of a sentence int indexEt = s.getRaw().indexOf(et.getName()); int currentDist = Math.abs((indexEt - indexT)); if (currentDist < minDist) { minDist = currentDist; nearest = et; } } if(nearest==null) { return -1; } int indexEt = s.getRaw().indexOf(nearest.getName()); try{ Task rightN = (Task) seq.getElementAt(indexEt+1); while(rightN.getName().equals(nearest)) rightN=(Task) seq.getElementAt(seq.indexOf(rightN)+1); } catch (IndexOutOfBoundsException ex) { } if (indexT < indexEt) { return seq.indexOf(nearest); } else { return seq.indexOf(nearest) + 1; } } public int getNextRelated(ArrayList senList, Sentence s, Sequence seq) { int ret=0; if (senList.indexOf(s) > 0) { // Get index of last task of the previous sentence ArrayList prevWfe = senList.get(senList.indexOf(s) - 1).getRelatedElem(); // For the case that more than one sentence without // related elements occurs find next sentence with // related items int skipIndex = 0; while (prevWfe.size() == 0) { skipIndex++; if (senList.indexOf(s) - skipIndex < 0) break; prevWfe = senList.get(senList.indexOf(s) - skipIndex) .getRelatedElem(); } // Get the index of the last related item of that // sentence int max = -1; for(WorkflowElement wfe : prevWfe) { if(seq.indexOf(wfe)>max) { max=seq.indexOf(wfe); } } ret=max; } if(senList.indexOf(s) ==0&s.getRelatedElem().size()>0) { ret=seq.indexOf(s.getRelatedElem().get(0)); } if(ret>-1) return ret; else return 0; } }