Search in sources :

Example 1 with QueuedOperationInformation

use of org.grupolys.samulan.util.QueuedOperationInformation in project uuusa by aghie.

the class SyntacticRuleBasedAnalyser method queueNodeOperations.

private void queueNodeOperations(List<Operation> operations, SentimentInformation si, SentimentDependencyNode node) {
    for (Operation o : operations) {
        short levelToApply = o.getRule().getLevelsup();
        if (o.getOperationName().equals(Operation.DEFAULT)) {
            si.setSemanticOrientation(getSemanticOrientation(node, o));
            int isPositiveSentiment = si.getSemanticOrientation() > 0 ? 1 : 0;
            int isNegativeSentiment = si.getSemanticOrientation() < 0 ? 1 : 0;
            si.setPositiveSentiment(Math.max(Math.abs(si.getSemanticOrientation()) * (isPositiveSentiment), SentimentInformation.SENTISTRENGTH_NEUTRAL));
            si.setNegativeSentiment(Math.max(Math.abs(si.getSemanticOrientation()) * (isNegativeSentiment), SentimentInformation.SENTISTRENGTH_NEUTRAL));
        }
        si.addQueueOperation(new QueuedOperationInformation(levelToApply, o));
    }
}
Also used : QueuedOperationInformation(org.grupolys.samulan.util.QueuedOperationInformation) Operation(org.grupolys.samulan.analyser.operation.Operation)

Example 2 with QueuedOperationInformation

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

Example 3 with QueuedOperationInformation

use of org.grupolys.samulan.util.QueuedOperationInformation in project uuusa by aghie.

the class SyntacticRuleBasedAnalyser method getOperationsToApply.

private PriorityQueue<QueuedOperationInformation> getOperationsToApply(List<QueuedOperationInformation> qois) {
    Comparator<QueuedOperationInformation> comparator = new Comparator<QueuedOperationInformation>() {

        public int compare(QueuedOperationInformation qoi1, QueuedOperationInformation qoi2) {
            return qoi2.getOperation().getPriority() - qoi1.getOperation().getPriority();
        }
    };
    PriorityQueue<QueuedOperationInformation> queuedOperations = new PriorityQueue<QueuedOperationInformation>(qois.size() + 1, comparator);
    for (QueuedOperationInformation qoi : qois) {
        if (!isPendingOperation(qoi)) {
            queuedOperations.add(qoi);
        }
    }
    return queuedOperations;
}
Also used : QueuedOperationInformation(org.grupolys.samulan.util.QueuedOperationInformation) PriorityQueue(java.util.PriorityQueue) Comparator(java.util.Comparator)

Example 4 with QueuedOperationInformation

use of org.grupolys.samulan.util.QueuedOperationInformation in project uuusa by aghie.

the class SyntacticRuleBasedAnalyser method getAllQueuedOperations.

private List<QueuedOperationInformation> getAllQueuedOperations(SentimentInformation head, List<SentimentInformation> children) {
    List<QueuedOperationInformation> allQueuedOperations = new ArrayList<QueuedOperationInformation>(head.getQueuedOperations());
    for (SentimentInformation siChild : children) {
        for (QueuedOperationInformation oChild : siChild.getQueuedOperations()) {
            // Nesting weighting operations
            // TODO only supports double nesting
            short headAddress = siChild.getSentimentDependencyNode().getHead();
            SentimentDependencyGraph sdgChild = siChild.getSentimentDependencyGraph();
            SentimentDependencyNode headNode = sdgChild.getNode(headAddress);
            String headLemma = this.rm.getD().getLemma(headNode.getCpostag(), headNode.getWord());
            SentimentDependencyNode grandPaNode = sdgChild.getNode(headNode.getHead());
            String grandPaLemma = this.rm.getD().getLemma(grandPaNode.getCpostag(), grandPaNode.getWord());
            boolean grandPaIsSubjective = this.rm.getD().getValue(grandPaNode.getCpostag(), grandPaLemma, true) != 0;
            if (this.rm.getD().isWeight(headLemma) && grandPaIsSubjective) {
                oChild.setLevelsUp((short) (oChild.getLevelsUp() + 1));
            }
            allQueuedOperations.add(oChild);
        }
    }
    return allQueuedOperations;
}
Also used : SentimentDependencyNode(org.grupolys.samulan.util.SentimentDependencyNode) SentimentDependencyGraph(org.grupolys.samulan.util.SentimentDependencyGraph) QueuedOperationInformation(org.grupolys.samulan.util.QueuedOperationInformation) ArrayList(java.util.ArrayList) SentimentInformation(org.grupolys.samulan.util.SentimentInformation)

Aggregations

QueuedOperationInformation (org.grupolys.samulan.util.QueuedOperationInformation)4 ArrayList (java.util.ArrayList)2 SentimentInformation (org.grupolys.samulan.util.SentimentInformation)2 Comparator (java.util.Comparator)1 PriorityQueue (java.util.PriorityQueue)1 Operation (org.grupolys.samulan.analyser.operation.Operation)1 OperationValue (org.grupolys.samulan.util.OperationValue)1 SentimentDependencyGraph (org.grupolys.samulan.util.SentimentDependencyGraph)1 SentimentDependencyNode (org.grupolys.samulan.util.SentimentDependencyNode)1