use of org.grupolys.samulan.util.OperationValue in project uuusa by aghie.
the class SyntacticRuleBasedAnalyser method calculate.
/**
* Given the SentimentInformation of a head term and its children, it computes the merged SentimentInformation
* that results after computing all operations to be applied at that stage.
* @param head: SentimentInformation object corresponding to the head (as a single node).
* @param children: List of SentimentInformation objects corresponding to the computed/merged SentimentInformation rooted at each child of the head term
* @return A new SentimentInformation corresponding to the computed/merged SentimentInformation rooted at the head term
*/
public SentimentInformation calculate(SentimentInformation head, List<SentimentInformation> children) {
List<QueuedOperationInformation> allOperations, qOperations;
PriorityQueue<QueuedOperationInformation> aOperations;
QueuedOperationInformation i;
OperationValue ov;
SentimentInformation newHead = new SentimentInformation(head);
allOperations = getAllQueuedOperations(newHead, children);
qOperations = getOperationsToQueue(allOperations);
aOperations = getOperationsToApply(allOperations);
String appliedOperations = "";
while ((i = aOperations.poll()) != null) {
ov = i.getOperation().apply(newHead, children);
// Logging the applied operation at node i
// TODO: Improve how we track.
appliedOperations = appliedOperations.concat(ov.appliedOperation() == null ? "" : ov.appliedOperation() + ",");
newHead = ov.getHead();
children = ov.getChildren();
}
this.ac.getSentimentJoiner().join(newHead, children);
// newHead has the reference to its graph
newHead.setSentimentInformationInGraph();
newHead.setOperationExplanation(appliedOperations);
// We add q(eued)Operations comming from the children to the head, to spread them through the tree
for (QueuedOperationInformation pd : qOperations) {
if (!newHead.getQueuedOperations().contains(pd)) {
newHead.getQueuedOperations().add(pd);
}
}
List<QueuedOperationInformation> aux = new ArrayList<QueuedOperationInformation>();
for (QueuedOperationInformation pd : newHead.getQueuedOperations()) {
if (isPendingOperation(pd)) {
aux.add(pd);
}
}
newHead.setQueuedOperations(aux);
updateLevelsUp(newHead.getQueuedOperations());
return newHead;
}
use of org.grupolys.samulan.util.OperationValue in project uuusa by aghie.
the class FirstSubjectiveChildrenStrategy method apply.
@Override
public OperationValue apply(SentimentInformation head, List<SentimentInformation> children, Operation operation) {
List<SentimentInformation> newChildren = new ArrayList<SentimentInformation>();
SentimentInformation auxChild;
boolean branchFound = false;
// System.out.println("Entra FirstSubjective");
for (SentimentInformation siChild : children) {
auxChild = new SentimentInformation(siChild);
if (!branchFound) {
// System.out.println("auxChild: "+auxChild);
if ((siChild.getSemanticOrientation() != 0) && (isOnRightSide(siChild.getSentimentDependencyNode().getAddress()))) {
// System.out.println("matched: "+auxChild);
operation.updateSentiment(auxChild);
// System.out.println("matched later: "+auxChild);
branchFound = true;
}
// System.out.println("matched later2: "+auxChild);
}
newChildren.add(auxChild);
}
if (!branchFound)
return null;
return new OperationValue(new SentimentInformation(head), newChildren);
}
use of org.grupolys.samulan.util.OperationValue in project uuusa by aghie.
the class NChildrenStrategy method apply.
/**
*/
public OperationValue apply(SentimentInformation head, List<SentimentInformation> children, Operation operation) {
// System.out.println("Entra NRightBrothersStrategy");
SentimentInformation auxHead = new SentimentInformation(head);
SentimentInformation auxChild;
List<SentimentInformation> newChildren = new ArrayList<SentimentInformation>();
int i = 0;
for (SentimentInformation siChild : children) {
auxChild = new SentimentInformation(siChild);
if (i < this.n && (isOnRightSide(siChild.getSentimentDependencyNode().getAddress()))) {
operation.updateSentiment(auxChild);
i += 1;
}
newChildren.add(auxChild);
}
return new OperationValue(auxHead, newChildren);
}
use of org.grupolys.samulan.util.OperationValue in project uuusa by aghie.
the class AbstractOperation method apply.
public OperationValue apply(SentimentInformation head, List<SentimentInformation> children) {
OperationValue ov = new OperationValue(head, children);
ov.setAppliedOperation(this);
ov.setAppliedStrategy(this.getStrategy());
return ov;
}
Aggregations