Search in sources :

Example 11 with SentimentInformation

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);
}
Also used : SentimentInformation(org.grupolys.samulan.util.SentimentInformation) ArrayList(java.util.ArrayList) OperationValue(org.grupolys.samulan.util.OperationValue)

Example 12 with SentimentInformation

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);
}
Also used : SentimentInformation(org.grupolys.samulan.util.SentimentInformation) ArrayList(java.util.ArrayList) OperationValue(org.grupolys.samulan.util.OperationValue)

Example 13 with SentimentInformation

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;
}
Also used : SentimentInformation(org.grupolys.samulan.util.SentimentInformation)

Example 14 with SentimentInformation

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;
}
Also used : SentimentInformation(org.grupolys.samulan.util.SentimentInformation) ArrayList(java.util.ArrayList)

Example 15 with SentimentInformation

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;
}
Also used : SentimentDependencyNode(org.grupolys.samulan.util.SentimentDependencyNode) NChildrenStrategy(org.grupolys.samulan.analyser.operation.NChildrenStrategy) ArrayList(java.util.ArrayList) SentimentInformation(org.grupolys.samulan.util.SentimentInformation) DefaultOperation(org.grupolys.samulan.analyser.operation.DefaultOperation) ShiftOperation(org.grupolys.samulan.analyser.operation.ShiftOperation) WeightingOperation(org.grupolys.samulan.analyser.operation.WeightingOperation) Operation(org.grupolys.samulan.analyser.operation.Operation) Rule(org.grupolys.samulan.rule.Rule) FirstSubjectiveChildrenStrategy(org.grupolys.samulan.analyser.operation.FirstSubjectiveChildrenStrategy)

Aggregations

SentimentInformation (org.grupolys.samulan.util.SentimentInformation)15 ArrayList (java.util.ArrayList)10 OperationValue (org.grupolys.samulan.util.OperationValue)6 SentimentDependencyNode (org.grupolys.samulan.util.SentimentDependencyNode)4 SentimentDependencyGraph (org.grupolys.samulan.util.SentimentDependencyGraph)3 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 FileNotFoundException (java.io.FileNotFoundException)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Writer (java.io.Writer)2 Operation (org.grupolys.samulan.analyser.operation.Operation)2 QueuedOperationInformation (org.grupolys.samulan.util.QueuedOperationInformation)2 HashMap (java.util.HashMap)1 CoNLLReader (org.grupolys.nlputils.parser.CoNLLReader)1 DependencyNode (org.grupolys.nlputils.parser.DependencyNode)1 DefaultOperation (org.grupolys.samulan.analyser.operation.DefaultOperation)1