use of org.w3._2007.rif.If in project poi by apache.
the class RelationshipTransformService method init.
@Override
public void init(XMLStructure parent, XMLCryptoContext context) throws InvalidAlgorithmParameterException {
LOG.log(POILogger.DEBUG, "init(parent,context)");
LOG.log(POILogger.DEBUG, "parent java type: " + parent.getClass().getName());
DOMStructure domParent = (DOMStructure) parent;
Node parentNode = domParent.getNode();
try {
TransformDocument transDoc = TransformDocument.Factory.parse(parentNode, DEFAULT_XML_OPTIONS);
XmlObject[] xoList = transDoc.getTransform().selectChildren(RelationshipReferenceDocument.type.getDocumentElementName());
if (xoList.length == 0) {
LOG.log(POILogger.WARN, "no RelationshipReference/@SourceId parameters present");
}
for (XmlObject xo : xoList) {
String sourceId = ((CTRelationshipReference) xo).getSourceId();
LOG.log(POILogger.DEBUG, "sourceId: ", sourceId);
this.sourceIds.add(sourceId);
}
} catch (XmlException e) {
throw new InvalidAlgorithmParameterException(e);
}
}
use of org.w3._2007.rif.If in project hale by halestudio.
the class TestModelRifToRifTranslator method checkJavaBindings.
private Sentence checkJavaBindings(Document result) {
assertNotNull(result);
assertNotNull(result.getPayload());
assertNotNull(result.getPayload().getGroup());
assertNotNull(result.getPayload().getGroup().getSentence());
assertThat(result.getPayload().getGroup().getSentence().size(), is(1));
Sentence actualSentence = result.getPayload().getGroup().getSentence().get(0);
assertNotNull(actualSentence.getImplies());
assertNotNull(actualSentence.getImplies().getIf());
assertNotNull(actualSentence.getImplies().getIf().getExists());
assertNotNull(actualSentence.getImplies().getThen());
assertNotNull(actualSentence.getImplies().getThen().getDo());
checkDoElements(actualSentence.getImplies().getThen().getDo());
// check contents of if
And and = checkDeclareElement(actualSentence);
checkAndChildren(and);
return actualSentence;
}
use of org.w3._2007.rif.If in project hale by halestudio.
the class TestModelRifToRifTranslator method testTranslateExample1NegationFilter.
/**
* Tests that it is possible to translate the example 3 CP source dataset,
* including a logical negation predicate filter.
*
* @throws TranslationException
* if any errors occurred during the translation
* @throws JAXBException
* if unable to write out a DOM document containing the RIF-PRD
*/
@Test
public void testTranslateExample1NegationFilter() throws TranslationException, JAXBException {
URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
"com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example1_tn_road.goml");
org.w3._2007.rif.Document doc = translator.translate(url);
assertNotNull(doc);
assertNotNull(doc.getPayload());
assertNotNull(doc.getPayload().getGroup());
assertNotNull(doc.getPayload().getGroup().getSentence());
// CHECKSTYLE:OFF
assertThat(doc.getPayload().getGroup().getSentence().size(), is(3));
// CHECKSTYLE:ON
assertNotNull(doc.getPayload().getGroup().getSentence().get(0));
writeDom(getDomFromRif(doc), System.out);
}
use of org.w3._2007.rif.If in project hale by halestudio.
the class ModelRifToRifTranslator method createExternalPredicateFilter.
private void createExternalPredicateFilter(ModelRifMappingCondition mappingCondition, Formula filterFormula) {
// create an <External>/<content>/<Atom> element hierarchy
ExternalFORMULAType external = factory.createExternalFORMULAType();
filterFormula.setExternal(external);
ContentFORMULAType content = factory.createContentFORMULAType();
external.setContent(content);
Atom atom = factory.createAtom();
content.setAtom(atom);
Op op = factory.createOp();
ArgsUNITERMType args = factory.createArgsUNITERMType();
atom.setOp(op);
Const opConst = factory.createConst();
// $NON-NLS-1$
opConst.setType("rif:iri");
opConst.getContent().add(mappingCondition.getOperator().getRifPredicate());
op.setConst(opConst);
atom.setArgs(args);
// $NON-NLS-1$
args.setOrdered("yes");
Var var = factory.createVar();
var.getContent().add(mappingCondition.getLeft().getName());
args.getTERM().add(var);
Const argsConst = factory.createConst();
argsConst.setType(getLiteralTypeFor(mappingCondition.getLiteralClass()));
String literalValue = mappingCondition.getLiteralValue().toString();
// remove any wildcards
if (mappingCondition.getOperator().equals(ComparisonType.STRING_CONTAINS)) {
// $NON-NLS-1$ //$NON-NLS-2$
literalValue = literalValue.replaceAll("%", "");
}
argsConst.getContent().add(literalValue);
args.getTERM().add(argsConst);
// $NON-NLS-1$ //$NON-NLS-2$
log.fine("Filter is a " + mappingCondition.getOperator().toString() + " filter");
}
use of org.w3._2007.rif.If in project hale by halestudio.
the class ModelRifToRifTranslator method createComparativeFilter.
private void createComparativeFilter(List<Formula> list, ModelRifMappingCondition mappingCondition) {
// $NON-NLS-1$
log.fine("Creating comparative filter");
Formula filterFormula = factory.createFormula();
list.add(filterFormula);
if (mappingCondition.getOperator().equals(ComparisonType.NUMBER_EQUALS) || mappingCondition.getOperator().equals(ComparisonType.STRING_EQUALS)) {
createEqualsFilter(mappingCondition, filterFormula);
} else if (mappingCondition.getOperator().equals(ComparisonType.NUMBER_GREATER_THAN) || mappingCondition.getOperator().equals(ComparisonType.NUMBER_LESS_THAN) || mappingCondition.getOperator().equals(ComparisonType.STRING_CONTAINS)) {
createExternalPredicateFilter(mappingCondition, filterFormula);
} else {
throw new UnsupportedOperationException(// $NON-NLS-1$
"Comparison type is not supported: " + mappingCondition.getOperator().toString());
}
}
Aggregations