use of org.grupolys.samulan.analyser.operation.Operation in project uuusa by aghie.
the class SyntacticRuleBasedAnalyser method analyse.
/**
* It computes the SentimentInformation of sentence represented as a SentimentDependencyGraph
* @param dg: The sentence represented as a SentimentDependencyGraph
* @param address: (usually the dummy root, id=0)
* @return The SentimentInformation for the branch of dg rooted at address
*/
public SentimentInformation analyse(SentimentDependencyGraph dg, short address) {
List<Operation> operations = this.rm.getOperations(dg, address);
SentimentInformation siHead;
SentimentDependencyNode node = (SentimentDependencyNode) dg.getNode(address);
siHead = new SentimentInformation(0, node, dg, new ArrayList<QueuedOperationInformation>());
// Queing operations in node
queueNodeOperations(operations, siHead, node);
if (node.isLeaf()) {
siHead = this.calculate(siHead, new ArrayList<SentimentInformation>());
return siHead;
} else {
List<Short> children = node.getDependents();
List<SentimentInformation> siChildren = new ArrayList<SentimentInformation>();
for (Short child : children) {
SentimentInformation siChild = this.analyse(dg, (short) child);
siChildren.add(siChild);
}
siHead = this.calculate(siHead, siChildren);
return siHead;
}
}
use of org.grupolys.samulan.analyser.operation.Operation 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));
}
}
use of org.grupolys.samulan.analyser.operation.Operation in project uuusa by aghie.
the class RuleManager method readRules.
public void readRules(String pathXML) {
Operation o;
try {
File file = new File(pathXML);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
// readAnalyserConfiguration(doc.getElementsByTagName("conf"));
NodeList nodeLst = doc.getElementsByTagName(OPERATION_FIELD);
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElement = (Element) fstNode;
Set<String> forms = new HashSet<String>(Arrays.asList(this.getXMLNodeValue(fstElement, FORM).split(",")));
Set<String> postags = new HashSet<String>(Arrays.asList(this.getXMLNodeValue(fstElement, POSTAG).split(",")));
Set<String> dependencies = new HashSet<String>(Arrays.asList(this.getXMLNodeValue(fstElement, DEPENDENCY).split(",")));
short levelsup = new Short(this.getXMLNodeValue(fstElement, LEVELSUP));
short priority = new Short(this.getXMLNodeValue(fstElement, PRIORITY));
HashSet<String> validHead = new HashSet<String>(Arrays.asList(this.getXMLNodeValue(fstElement, VALID_HEAD).split(",")));
// TODO process regex
postags.remove("*");
// TODO process regex
dependencies.remove("*");
// TODO process regex
validHead.remove("*");
// INTENSIFICATION RULES WITH SENTIDATA
if (forms.contains(SENTIDATA_BOOSTER)) {
if (forms.size() == 1) {
// System.out.println("getClassValues: "+this.d.getClassValues());
if (this.d.getClassValues().get(Operation.WEIGHT) != null) {
addRules(fstElement, this.d.getClassValues().get(Operation.WEIGHT).keySet(), postags, dependencies, levelsup, priority, validHead);
}
} else {
System.err.println("We cannot handle ");
}
} else // NEGATION RULES WITH SENTIDATA
if (forms.contains(SENTIDATA_NEGATION)) {
if (forms.size() == 1) {
addRules(fstElement, this.d.getNegatingWords(), postags, dependencies, levelsup, priority, validHead);
} else {
System.err.println("We cannot handle this kind of rules " + forms);
}
} else // OTHER RULES
{
// TODO process regex
forms.remove("*");
if (forms.contains(SENTIDATA_ADVERSATIVE)) {
forms.addAll(this.d.getAdversativeWords());
}
// System.out.println(forms+" "+priority);
addRules(fstElement, forms, postags, dependencies, levelsup, priority, validHead);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.grupolys.samulan.analyser.operation.Operation 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;
}
use of org.grupolys.samulan.analyser.operation.Operation in project uuusa by aghie.
the class RuleManager method addRules.
private void addRules(Element fstElement, Set<String> sentiForms, Set<String> postags, Set<String> dependencies, short levelsup, short priority, Set<String> validHead) {
for (String sentiForm : sentiForms) {
Operation o = getOperationFinal(this.getXMLNodeValue(fstElement, TYPE), sentiForm);
if (o != null) {
Set<String> patternForms = new HashSet<String>();
Set<Pattern> patterns = new HashSet<Pattern>();
if (isNonRegexForm(sentiForm)) {
patterns = new HashSet<Pattern>(Arrays.asList(Pattern.compile(sentiForm)));
} else {
patternForms = new HashSet<String>(Arrays.asList(sentiForm));
}
Rule r = new Rule(patterns, patternForms, postags, dependencies, levelsup, priority, validHead, o);
this.addRule(r);
}
}
}
Aggregations