use of org.grupolys.samulan.util.SentimentInformation 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.SentimentInformation 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.SentimentInformation in project uuusa by aghie.
the class NormaliserSentimentJoiner method join.
@Override
public SentimentInformation join(SentimentInformation head, List<SentimentInformation> children) {
float nPositiveSentiment = 0;
float nNegativeSentiment = 0;
head.setPositiveSentiment(normalise(head.getPositiveSentiment()));
head.setNegativeSentiment(normalise(head.getNegativeSentiment()));
for (SentimentInformation siChild : children) {
nPositiveSentiment = normalise(nPositiveSentiment + siChild.getPositiveSentiment());
nNegativeSentiment = normalise(nNegativeSentiment + siChild.getNegativeSentiment());
}
head.setPositiveSentiment(normalise(head.getPositiveSentiment() + nPositiveSentiment));
head.setNegativeSentiment(normalise(head.getNegativeSentiment() + nNegativeSentiment));
head.setSemanticOrientation(head.getPositiveSentiment() - head.getNegativeSentiment());
return head;
}
use of org.grupolys.samulan.util.SentimentInformation in project uuusa by aghie.
the class CompositeSentimentJoiner method join.
@Override
public SentimentInformation join(SentimentInformation head, List<SentimentInformation> children) {
List<SentimentInformation> auxChildren;
auxChildren = children.stream().map((SentimentInformation c) -> new SentimentInformation(c)).collect(Collectors.toList());
for (SentimentJoiner sj : joiners) {
// System.out.println(sj);
// Each child is joined as a single node, to avoid replications
auxChildren = auxChildren.stream().map((SentimentInformation c) -> sj.join(c, new ArrayList<SentimentInformation>())).collect(Collectors.toList());
// The head is 'joined' separately as well
head = sj.join(head, new ArrayList<SentimentInformation>());
// Joining head and children
head = sj.join(head, auxChildren);
}
return head;
}
use of org.grupolys.samulan.util.SentimentInformation in project uuusa by aghie.
the class RuleManager method getOperations.
/**
* @param dg
* @param address
* @return
*/
public List<Operation> getOperations(SentimentDependencyGraph dg, short address) {
SentimentDependencyNode currentNode = dg.getNode(address);
List<Operation> operations = new ArrayList<Operation>();
for (Rule r : rules) {
if (r.match(dg, currentNode)) {
Operation o = r.getOperation();
// System.out.println("currentNode: "+currentNode+" r: "+r+" o: "+o);
if (dg.getNode(address).getSi() == null)
dg.getNode(address).setSi(new SentimentInformation());
if (!o.getOperationName().equals(Operation.DEFAULT)) {
dg.getNode(address).getSi().setType(o.getOperationName());
if (o.getStrategy() instanceof NChildrenStrategy) {
((NChildrenStrategy) o.getStrategy()).setReference(address);
}
if (o.getStrategy() instanceof FirstSubjectiveChildrenStrategy) {
((FirstSubjectiveChildrenStrategy) o.getStrategy()).setReference(address);
}
}
operations.add(r.getOperation());
}
}
if (operations.contains(getOperation(Operation.DEFAULT)) && operations.size() > 1)
operations.remove(getOperation(Operation.DEFAULT));
return operations;
}
Aggregations