use of org.apache.stanbol.rules.base.api.RuleAtom in project stanbol by apache.
the class DatavaluedPropertyAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom) ruleAtom;
IObjectAtom argument1 = tmp.getArgument1();
IObjectAtom datatypeProperty = tmp.getDatatypeProperty();
RuleAtom argument2 = tmp.getArgument2();
ClauseEntry argument2ClauseEntry = adapter.adaptTo(argument2, Rule.class);
ClauseEntry argument1ClauseEntry = adapter.adaptTo(argument1, Rule.class);
ClauseEntry datatypePropertyClauseEntry = adapter.adaptTo(datatypeProperty, Rule.class);
Node subjectNode = null;
Node predicateNode = null;
Node objectNode = null;
if (argument1ClauseEntry instanceof NodeClauseEntry) {
subjectNode = ((NodeClauseEntry) argument1ClauseEntry).getNode();
} else {
throw new RuleAtomCallExeption(getClass());
}
if (datatypePropertyClauseEntry instanceof NodeClauseEntry) {
predicateNode = ((NodeClauseEntry) datatypePropertyClauseEntry).getNode();
} else {
throw new RuleAtomCallExeption(getClass());
}
if (argument2ClauseEntry instanceof NodeClauseEntry) {
objectNode = ((NodeClauseEntry) argument2ClauseEntry).getNode();
} else {
throw new RuleAtomCallExeption(getClass());
}
return (T) new TriplePattern(subjectNode, predicateNode, objectNode);
}
use of org.apache.stanbol.rules.base.api.RuleAtom in project stanbol by apache.
the class DatavaluedPropertyAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom) ruleAtom;
IObjectAtom argument1 = tmp.getArgument1();
IObjectAtom datatypeProperty = tmp.getDatatypeProperty();
RuleAtom argument2 = tmp.getArgument2();
ClerezzaSparqlObject argument1CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
ClerezzaSparqlObject datatypePropertyCSO = (ClerezzaSparqlObject) adapter.adaptTo(datatypeProperty, ConstructQuery.class);
ClerezzaSparqlObject argument2CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
Object arg1 = argument1CSO.getClerezzaObject();
Object dt = datatypePropertyCSO.getClerezzaObject();
Object arg2 = argument2CSO.getClerezzaObject();
UriRefOrVariable subject;
UriRefOrVariable predicate;
ResourceOrVariable object;
if (arg1 instanceof Variable) {
subject = new UriRefOrVariable((Variable) arg1);
} else if (arg1 instanceof IRI) {
subject = new UriRefOrVariable((IRI) arg1);
} else {
throw new RuleAtomCallExeption(getClass());
}
if (dt instanceof Variable) {
predicate = new UriRefOrVariable((Variable) dt);
} else if (dt instanceof IRI) {
predicate = new UriRefOrVariable((IRI) dt);
} else {
throw new RuleAtomCallExeption(getClass());
}
if (arg2 instanceof Variable) {
object = new ResourceOrVariable((Variable) arg2);
} else if (arg2 instanceof LiteralExpression) {
object = new ResourceOrVariable(((LiteralExpression) arg2).getLiteral());
} else {
throw new RuleAtomCallExeption(getClass());
}
return (T) new ClerezzaSparqlObject(new SimpleTriplePattern(subject, predicate, object));
}
use of org.apache.stanbol.rules.base.api.RuleAtom in project stanbol by apache.
the class RuleImpl method prettyPrint.
@Override
public String prettyPrint() {
String rule = null;
String tab = " ";
if (head != null && body != null) {
boolean addAnd = false;
rule = "RULE " + ruleName + " ASSERTS THAT " + System.getProperty("line.separator");
rule += "IF" + System.getProperty("line.separator");
for (RuleAtom atom : body) {
rule += tab;
if (addAnd) {
rule += "AND ";
} else {
addAnd = true;
}
rule += atom.toString() + System.getProperty("line.separator");
}
rule += "IMPLIES" + System.getProperty("line.separator");
addAnd = false;
for (RuleAtom atom : head) {
rule += tab;
if (addAnd) {
rule += "AND ";
} else {
addAnd = true;
}
rule += atom.toString() + System.getProperty("line.separator");
}
}
return rule;
}
use of org.apache.stanbol.rules.base.api.RuleAtom in project stanbol by apache.
the class AtomList method remove.
public boolean remove(Object o) {
boolean removed = false;
for (int i = 0; i < kReSRuleAtoms.length && !removed; i++) {
RuleAtom semionRule = kReSRuleAtoms[i];
if (semionRule.equals(o)) {
RuleAtom[] semionRulesCopy = new RuleAtom[kReSRuleAtoms.length - 1];
System.arraycopy(kReSRuleAtoms, 0, semionRulesCopy, 0, i);
System.arraycopy(kReSRuleAtoms, i + 1, semionRulesCopy, 0, semionRulesCopy.length - i);
kReSRuleAtoms = semionRulesCopy;
removed = true;
}
}
return removed;
}
use of org.apache.stanbol.rules.base.api.RuleAtom in project stanbol by apache.
the class AtomList method removeAll.
public boolean removeAll(Collection<?> c) {
if (contains(c)) {
for (Object o : c) {
boolean removed = false;
for (int i = 0; i < kReSRuleAtoms.length && !removed; i++) {
RuleAtom semionRule = kReSRuleAtoms[i];
if (semionRule.equals(o)) {
RuleAtom[] semionRulesCopy = new RuleAtom[kReSRuleAtoms.length - 1];
System.arraycopy(kReSRuleAtoms, 0, semionRulesCopy, 0, i);
System.arraycopy(kReSRuleAtoms, i + 1, semionRulesCopy, 0, semionRulesCopy.length - i);
kReSRuleAtoms = semionRulesCopy;
removed = true;
}
}
}
return true;
} else {
return false;
}
}
Aggregations