source: trunk/quest-core-tasktrees/src/main/java/de/ugoe/cs/quest/tasktrees/temporalrelation/TemporalRelationshipRuleManager.java @ 439

Last change on this file since 439 was 439, checked in by pharms, 12 years ago

initial import after refactoring of module structure with Steffen

  • Property svn:executable set to *
File size: 5.9 KB
Line 
1//-------------------------------------------------------------------------------------------------
2// Module    : $RCSfile: TemporalRelationshipRuleManager.java,v $
3// Version   : $Revision: 0.0 $  $Author: patrick $  $Date: 12.02.2012 $
4// Project   : TaskTreeCreator
5// Creation  : 2012 by patrick
6// Copyright : Patrick Harms, 2012
7//-------------------------------------------------------------------------------------------------
8package de.ugoe.cs.quest.tasktrees.temporalrelation;
9
10import java.util.ArrayList;
11import java.util.List;
12import java.util.logging.Logger;
13
14import de.ugoe.cs.quest.tasktrees.nodeequality.NodeEqualityRuleManager;
15import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder;
16import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode;
17import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory;
18
19//-------------------------------------------------------------------------------------------------
20/**
21 * TODO comment
22 *
23 * @version $Revision: $ $Date: 12.02.2012$
24 * @author 2012, last modified by $Author: patrick$
25 */
26//-------------------------------------------------------------------------------------------------
27public class TemporalRelationshipRuleManager
28{
29  /** */
30  private static Logger LOG = Logger.getLogger(TemporalRelationshipRuleManager.class.getName());
31
32  /** */
33  private NodeEqualityRuleManager mNodeEqualityRuleManager;
34
35  /** */
36  private List<TemporalRelationshipRule> mRuleIndex = new ArrayList<TemporalRelationshipRule>();
37
38  //-----------------------------------------------------------------------------------------------
39  /**
40   * TODO: comment
41   *
42   */
43  //-----------------------------------------------------------------------------------------------
44  public TemporalRelationshipRuleManager(NodeEqualityRuleManager nodeEqualityRuleManager)
45  {
46    super();
47    mNodeEqualityRuleManager = nodeEqualityRuleManager;
48  }
49
50  //-----------------------------------------------------------------------------------------------
51  /**
52   * TODO: comment
53   *
54   */
55  //-----------------------------------------------------------------------------------------------
56  public void init()
57  {
58    LOG.info("initializing");
59   
60    mRuleIndex.add(new DefaultMouseClickReductionRule());
61    mRuleIndex.add(new DefaultTextInputReductionRule());
62    mRuleIndex.add(new DefaultGUIElementSequenceDetectionRule());
63    mRuleIndex.add(new TrackBarSelectionDetectionRule(mNodeEqualityRuleManager));
64    mRuleIndex.add(new DefaultSequenceDetectionRule());
65    mRuleIndex.add(new DefaultIterationDetectionRule(mNodeEqualityRuleManager));
66  }
67
68  //-----------------------------------------------------------------------------------------------
69  /**
70   * returns true, if there is a rule that matches the current situation and if, therefore, a
71   * new temporal relationship has been added to the tree.
72   *
73   * @param parent
74   * @param newChild
75   * @return
76   */
77  //-----------------------------------------------------------------------------------------------
78  public void applyRules(TaskTreeNode        parent,
79                         TaskTreeBuilder     builder,
80                         TaskTreeNodeFactory nodeFactory,
81                         boolean             finalize)
82  {
83    applyRules(parent, builder, nodeFactory, finalize, "");
84  }
85
86  //-----------------------------------------------------------------------------------------------
87  /**
88   * returns true, if there is a rule that matches the current situation and if, therefore, a
89   * new temporal relationship has been added to the tree.
90   *
91   * @param parent
92   * @param newChild
93   * @return
94   */
95  //-----------------------------------------------------------------------------------------------
96  private int applyRules(TaskTreeNode        parent,
97                         TaskTreeBuilder     builder,
98                         TaskTreeNodeFactory nodeFactory,
99                         boolean             finalize,
100                         String              logIndent)
101  {
102    LOG.info(logIndent + "applying rules for " + parent);
103   
104    int noOfRuleApplications = 0;
105   
106    for (TemporalRelationshipRule rule : mRuleIndex)
107    {
108      RuleApplicationResult result;
109      do
110      {
111        //LOG.info(logIndent + "trying to apply rule " + rule + " on " + parent);
112        result = rule.apply(parent, builder, nodeFactory, finalize);
113       
114        if ((result != null) &&
115            (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FINISHED))
116        {
117          LOG.info(logIndent + "applied rule " + rule + " on " + parent);
118          noOfRuleApplications++;
119         
120          for (TaskTreeNode newParent : result.getNewlyCreatedParentNodes())
121          {
122            noOfRuleApplications +=
123              applyRules(newParent, builder, nodeFactory, true, logIndent + "  ");
124          }
125        }
126      }
127      while ((result != null) &&
128             (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FINISHED));
129     
130      if ((!finalize) && (result != null) &&
131          (result.getRuleApplicationStatus() == RuleApplicationStatus.RULE_APPLICATION_FEASIBLE))
132      {
133        // in this case, don't go on applying rules, which should not be applied yet
134        break;
135      }
136    }
137   
138    if (noOfRuleApplications <= 0)
139    {
140      LOG.warning(logIndent + "no rules applied --> no temporal relationship generated");
141    }
142   
143    return noOfRuleApplications;
144  }
145 
146  //-----------------------------------------------------------------------------------------------
147  /**
148   *
149   */
150  //-----------------------------------------------------------------------------------------------
151  /*private void dumpTask(TaskTreeNode task, String indent)
152  {
153    System.err.print(indent);
154    System.err.print(task);
155    System.err.println(" ");
156   
157    if ((task.getChildren() != null) && (task.getChildren().size() > 0))
158    {
159      for (TaskTreeNode child : task.getChildren())
160      {
161        dumpTask(child, indent + "  ");
162      }
163    }
164  }*/
165
166}
Note: See TracBrowser for help on using the repository browser.