You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by an...@apache.org on 2012/03/28 15:55:26 UTC
svn commit: r1306329 [1/2] - in /incubator/stanbol/trunk/rules/adapters: ./
src/main/java/org/apache/stanbol/rules/adapters/jena/
src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/
src/test/java/org/apache/stanbol/rules/adapters/ src/test/java...
Author: anuzzolese
Date: Wed Mar 28 13:55:24 2012
New Revision: 1306329
URL: http://svn.apache.org/viewvc?rev=1306329&view=rev
Log:
Initial commit of the rule adapter for Jena rules.
Added:
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/HigherOrderClauseEntry.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/JenaAdapter.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeClauseEntry.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeFactory.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/BlankNodeAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ClassAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ConcatAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/CreateLabelAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DatavaluedPropertyAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DifferentAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DivisionAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/EndsWithAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterEqualThanAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterThanAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IndividualPropertyAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IsBlankAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LengthAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessEqualThanAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessThanAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LetAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LocalNameAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LowerCaseAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/MultiplicationAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/NamespaceAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/NewIRIAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/NewLiteralAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/NotAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/NumberAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/NumericVariableAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/PropStringAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ResourceAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/SameAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/StartsWithAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/StrAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/StringAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/StringVariableAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/SubstringAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/SubtractionAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/SumAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/TypedLiteralAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/UObjectAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/UnionAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/UpperCaseAtom.java
incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/VariableAtom.java
incubator/stanbol/trunk/rules/adapters/src/test/java/org/apache/stanbol/rules/adapters/
incubator/stanbol/trunk/rules/adapters/src/test/java/org/apache/stanbol/rules/adapters/jena/
incubator/stanbol/trunk/rules/adapters/src/test/java/org/apache/stanbol/rules/adapters/jena/JenaAdpterTest.java
Modified:
incubator/stanbol/trunk/rules/adapters/pom.xml
incubator/stanbol/trunk/rules/adapters/target/maven-shared-archive-resources/META-INF/DEPENDENCIES
incubator/stanbol/trunk/rules/adapters/target/maven-shared-archive-resources/META-INF/NOTICE
Modified: incubator/stanbol/trunk/rules/adapters/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/pom.xml?rev=1306329&r1=1306328&r2=1306329&view=diff
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/pom.xml (original)
+++ incubator/stanbol/trunk/rules/adapters/pom.xml Wed Mar 28 13:55:24 2012
@@ -22,10 +22,10 @@
</parent>
<groupId>org.apache.stanbol</groupId>
- <artifactId>org.apache.stanbol.rules.adapters</artifactId>
+ <artifactId>org.apache.stanbol.rules.adapters.jena</artifactId>
<packaging>bundle</packaging>
- <name>Apache Stanbol Rules - Adapters</name>
+ <name>Apache Stanbol Rules - Jena Rules Adapters</name>
<description>
The set of functionalities for manipulating
inference rules, complete with built-in atoms.
@@ -46,7 +46,7 @@
META-INF
</Bundle-ClassPath>
<Export-Package>
- org.apache.stanbol.rules.adapters.*
+ org.apache.stanbol.rules.adapters.jena.*
</Export-Package>
<Import-Package>
org.slf4j.*,
@@ -71,12 +71,28 @@
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
+
+ <!-- Jena deps -->
+ <dependency>
+ <groupId>com.hp.hpl.jena</groupId>
+ <artifactId>jena</artifactId>
+ </dependency>
+
<!-- Stanbol deps -->
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.rules.base</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.rules.manager</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.rules.adapters</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ </dependency>
+
<!-- Testing deps -->
<dependency>
<groupId>junit</groupId>
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/HigherOrderClauseEntry.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/HigherOrderClauseEntry.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/HigherOrderClauseEntry.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/HigherOrderClauseEntry.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters.jena;
+
+import java.util.List;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+
+/**
+ * It is used for represent higher order atoms.<br/>
+ * It is used to convert Stanbol atoms that accept other atoms as arguments, such as
+ * <code>sum(sum(5,?x), ?y)</code>.<br/>
+ * In such a situation in Jena we should use new variables as place holders, e.g., sum(?ph1, ?y, ?z) sum(5,
+ * ?x, ?ph1).
+ *
+ * @author anuzzolese
+ *
+ */
+public class HigherOrderClauseEntry implements ClauseEntry {
+
+ private Node bindableNode;
+ private List<ClauseEntry> clauseEntries;
+
+ public HigherOrderClauseEntry(Node bindableNode, List<ClauseEntry> clauseEntries) {
+ this.bindableNode = bindableNode;
+ this.clauseEntries = clauseEntries;
+ }
+
+ public HigherOrderClauseEntry() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public boolean sameAs(Object o) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Node getBindableNode() {
+ return bindableNode;
+ }
+
+ public List<ClauseEntry> getClauseEntries() {
+ return clauseEntries;
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/JenaAdapter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/JenaAdapter.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/JenaAdapter.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/JenaAdapter.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters.jena;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.stanbol.rules.adapters.AbstractRuleAdapter;
+import org.apache.stanbol.rules.adapters.AdaptableAtom;
+import org.apache.stanbol.rules.base.api.Adaptable;
+import org.apache.stanbol.rules.base.api.Recipe;
+import org.apache.stanbol.rules.base.api.Rule;
+import org.apache.stanbol.rules.base.api.RuleAdapter;
+import org.apache.stanbol.rules.base.api.RuleAdaptersFactory;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.RuleStore;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.base.api.util.AtomList;
+import org.apache.stanbol.rules.base.api.util.RuleList;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+
+/**
+ * The adapter for Jena rules. <br/>
+ * The output object of this adapter is a {@link com.hp.hpl.jena.reasoner.rulesys.Rule} instance.<br/>
+ * For that reason the adaptTo method works only if the second argument is
+ * <code>com.hp.hpl.jena.reasoner.rulesys.Rule.class</code>
+ *
+ * @author anuzzolese
+ *
+ */
+
+@Component(immediate = true, metatype = true)
+@Service(RuleAdapter.class)
+public class JenaAdapter extends AbstractRuleAdapter {
+
+ public static final String ARTIFACT = "org.apache.stanbol.rules.adapters.jena.atoms";
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference
+ RuleStore ruleStore;
+
+ @Reference
+ RuleAdaptersFactory ruleAdaptersFactory;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected <T> T adaptRecipeTo(Recipe recipe, Class<T> type) throws RuleAtomCallExeption,
+ UnsupportedTypeForExportException,
+ UnavailableRuleObjectException {
+
+ List<com.hp.hpl.jena.reasoner.rulesys.Rule> jenaRules = null;
+
+ if (type == com.hp.hpl.jena.reasoner.rulesys.Rule.class) {
+
+ RuleList ruleList = recipe.getRuleList();
+ Iterator<Rule> ruleIterator = ruleList.iterator();
+
+ jenaRules = new ArrayList<com.hp.hpl.jena.reasoner.rulesys.Rule>();
+ for (int i = 0; ruleIterator.hasNext(); i++) {
+ jenaRules.add((com.hp.hpl.jena.reasoner.rulesys.Rule) adaptRuleTo(ruleIterator.next(), type));
+ }
+
+ } else {
+ throw new UnsupportedTypeForExportException(
+ "The Jena Adapter does not support the selected serialization : "
+ + type.getCanonicalName());
+ }
+
+ return (T) jenaRules;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected <T> T adaptRuleTo(Rule rule, Class<T> type) throws RuleAtomCallExeption,
+ UnsupportedTypeForExportException,
+ UnavailableRuleObjectException {
+
+ if (type == com.hp.hpl.jena.reasoner.rulesys.Rule.class) {
+ AtomList bodyAtomList = rule.getBody();
+ AtomList headAtomList = rule.getHead();
+
+ List<ClauseEntry> headClauseEntries = new ArrayList<ClauseEntry>();
+ List<ClauseEntry> bodyClauseEntries = new ArrayList<ClauseEntry>();
+
+ Iterator<RuleAtom> it = headAtomList.iterator();
+ while (it.hasNext()) {
+ RuleAtom atom = it.next();
+ ClauseEntry clauseEntry = adaptRuleAtomTo(atom, com.hp.hpl.jena.reasoner.rulesys.Rule.class);
+
+ if (clauseEntry instanceof HigherOrderClauseEntry) {
+ List<ClauseEntry> clauseEntries = ((HigherOrderClauseEntry) clauseEntry)
+ .getClauseEntries();
+
+ for (ClauseEntry ce : clauseEntries) {
+ headClauseEntries.add(ce);
+ }
+ } else {
+ headClauseEntries.add(clauseEntry);
+ }
+ }
+
+ it = bodyAtomList.iterator();
+ while (it.hasNext()) {
+ RuleAtom atom = it.next();
+ ClauseEntry clauseEntry = adaptRuleAtomTo(atom, com.hp.hpl.jena.reasoner.rulesys.Rule.class);
+
+ if (clauseEntry instanceof HigherOrderClauseEntry) {
+ List<ClauseEntry> clauseEntries = ((HigherOrderClauseEntry) clauseEntry)
+ .getClauseEntries();
+
+ for (ClauseEntry ce : clauseEntries) {
+ bodyClauseEntries.add(ce);
+ }
+ } else {
+ bodyClauseEntries.add(clauseEntry);
+ }
+ }
+
+ return (T) new com.hp.hpl.jena.reasoner.rulesys.Rule(rule.getRuleName(), headClauseEntries,
+ bodyClauseEntries);
+ } else {
+ throw new UnsupportedTypeForExportException("The adapter " + getClass()
+ + " does not support type : "
+ + type.getCanonicalName());
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected <T> T adaptRuleAtomTo(RuleAtom ruleAtom, Class<T> type) throws RuleAtomCallExeption,
+ UnsupportedTypeForExportException,
+ UnavailableRuleObjectException {
+
+ if (type == com.hp.hpl.jena.reasoner.rulesys.Rule.class) {
+
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+ String className = ruleAtom.getClass().getSimpleName();
+
+ String canonicalName = ARTIFACT + "." + className;
+
+ try {
+ Class<AdaptableAtom> jenaAtomClass = (Class<AdaptableAtom>) loader.loadClass(canonicalName);
+
+ try {
+ AdaptableAtom jenaAtom = jenaAtomClass.newInstance();
+
+ jenaAtom.setRuleAdapter(this);
+
+ return (T) jenaAtom.adapt(ruleAtom);
+
+ } catch (InstantiationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ } else {
+ throw new UnsupportedTypeForExportException("The adapter " + getClass()
+ + " does not support type : "
+ + type.getCanonicalName());
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Used to configure an instance within an OSGi container.
+ *
+ * @throws IOException
+ */
+ @SuppressWarnings("unchecked")
+ @Activate
+ protected void activate(ComponentContext context) throws IOException {
+
+ log.info("in " + JenaAdapter.class + " activate with context " + context);
+ if (context == null) {
+ throw new IllegalStateException("No valid" + ComponentContext.class + " parsed in activate!");
+ }
+ activate((Dictionary<String,Object>) context.getProperties());
+ }
+
+ /**
+ * Should be called within both OSGi and non-OSGi environments.
+ *
+ * @param configuration
+ * @throws IOException
+ */
+ protected void activate(Dictionary<String,Object> configuration) throws IOException {
+
+ log.info("The Jena Adapter for Stanbol Rules is active", this);
+ }
+
+ @Deactivate
+ protected void deactivate(ComponentContext context) {
+ log.info("in " + JenaAdapter.class + " deactivate with context " + context);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> Class<T> getExportClass() {
+ return (Class<T>) com.hp.hpl.jena.reasoner.rulesys.Rule.class;
+ }
+
+ @Override
+ public <T> boolean canAdaptTo(Adaptable adaptable, Class<T> type) {
+ if(type == com.hp.hpl.jena.reasoner.rulesys.Rule.class){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeClauseEntry.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeClauseEntry.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeClauseEntry.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeClauseEntry.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters.jena;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+
+/**
+ * A wrapper in order to treat a node as a {@link ClauseEntry}
+ *
+ * @author anuzzolese
+ *
+ */
+public class NodeClauseEntry implements ClauseEntry {
+
+ private Node node;
+
+ public NodeClauseEntry(Node node) {
+ this.node = node;
+ }
+
+ @Override
+ public boolean sameAs(Object o) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /**
+ * Get the node that is an instance of the class {@link Node}.
+ *
+ * @return the node
+ */
+ public Node getNode() {
+ return node;
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeFactory.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeFactory.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/NodeFactory.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters.jena;
+
+import org.apache.stanbol.rules.base.api.URIResource;
+import org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom;
+
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable;
+import com.hp.hpl.jena.vocabulary.XSD;
+
+/**
+ * It provides a static method (<code>getTypedLiteral</code>) that allows to convert an object to {@link Node}
+ * that implements a typed literal in Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class NodeFactory {
+
+ /**
+ * The argument is converted to a Jena {@link Node}
+ *
+ * @param argument
+ * any Object
+ * @return the {@link Node}
+ */
+ public static Node getTypedLiteral(Object argument) {
+
+ Node literal;
+ if (argument instanceof TypedLiteralAtom) {
+ TypedLiteralAtom typedLiteralAtom = (TypedLiteralAtom) argument;
+
+ URIResource xsdType = typedLiteralAtom.getXsdType();
+
+ if (xsdType.getURI().equals(XSD.xboolean)) {
+ literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDboolean);
+ } else if (xsdType.getURI().equals(XSD.xdouble)) {
+ literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDdouble);
+ } else if (xsdType.getURI().equals(XSD.xfloat)) {
+ literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDfloat);
+ } else if (xsdType.getURI().equals(XSD.xint)) {
+ literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDint);
+ } else {
+ literal = Node_RuleVariable.createLiteral(argument.toString());
+ }
+ } else if (argument instanceof String) {
+ literal = Node_RuleVariable.createLiteral((String) argument, null, XSDDatatype.XSDstring);
+ } else if (argument instanceof Integer) {
+ literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDinteger);
+ } else if (argument instanceof Double) {
+ literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDdouble);
+ } else if (argument instanceof Float) {
+ literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDfloat);
+ } else if (argument instanceof Boolean) {
+ literal = Node_RuleVariable.createLiteral(argument.toString(), null, XSDDatatype.XSDboolean);
+ } else {
+ literal = Node_RuleVariable.createLiteral((String) argument);
+ }
+
+ return literal;
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/BlankNodeAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/BlankNodeAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/BlankNodeAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/BlankNodeAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.IObjectAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.TriplePattern;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts a BlankNodeAtom to triple pattern of Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class BlankNodeAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ org.apache.stanbol.rules.manager.atoms.BlankNodeAtom tmp = (org.apache.stanbol.rules.manager.atoms.BlankNodeAtom) ruleAtom;
+
+ IObjectAtom argument1 = tmp.getArgument1();
+ IObjectAtom argument2 = tmp.getArgument2();
+
+ ClauseEntry argument1CE = (ClauseEntry) adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry argument2CE = (ClauseEntry) adapter.adaptTo(argument2, Rule.class);
+
+ Node arg1Node;
+ Node arg2Node;
+
+ if (argument1CE instanceof NodeClauseEntry) {
+ arg1Node = ((NodeClauseEntry) argument1CE).getNode();
+ } else {
+ throw new RuleAtomCallExeption(getClass());
+ }
+
+ if (argument2CE instanceof NodeClauseEntry) {
+ arg2Node = ((NodeClauseEntry) argument2CE).getNode();
+ } else {
+ throw new RuleAtomCallExeption(getClass());
+ }
+
+ Node blank = Node_RuleVariable.createAnon();
+
+ return (T) new TriplePattern(arg2Node, arg1Node, blank);
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ClassAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ClassAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ClassAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ClassAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.IObjectAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.TriplePattern;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+/**
+ *
+ * It adapts a ClassAtom to triple pattern of Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class ClassAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
+
+ IObjectAtom argument1 = tmp.getArgument1();
+ IObjectAtom classResource = tmp.getClassResource();
+
+ ClauseEntry argumentClauseEntry = (ClauseEntry) adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry classClauseEntry = (ClauseEntry) adapter.adaptTo(classResource, Rule.class);
+
+ Node argumnetNode;
+ Node classNode;
+
+ if (argumentClauseEntry instanceof NodeClauseEntry) {
+ argumnetNode = ((NodeClauseEntry) argumentClauseEntry).getNode();
+ } else {
+ throw new RuleAtomCallExeption(getClass());
+ }
+
+ if (classClauseEntry instanceof NodeClauseEntry) {
+ classNode = ((NodeClauseEntry) classClauseEntry).getNode();
+ } else {
+ throw new RuleAtomCallExeption(getClass());
+ }
+
+ return (T) new TriplePattern(argumnetNode, Node_RuleVariable.createURI(RDF.type.getURI()), classNode);
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ConcatAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ConcatAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ConcatAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/ConcatAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.ExpressionAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Functor;
+import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts any ConcatAtom to a strConcat functor in Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class ConcatAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ String concat_result = "concat_result" + System.currentTimeMillis();
+
+ Node arg1Node = null;
+ Node arg2Node = null;
+ Node resultNode = Node_RuleVariable.createVariable(concat_result);
+ ;
+
+ org.apache.stanbol.rules.manager.atoms.ConcatAtom tmp = (org.apache.stanbol.rules.manager.atoms.ConcatAtom) ruleAtom;
+
+ ExpressionAtom argument1 = tmp.getArgument1();
+ ExpressionAtom argument2 = tmp.getArgument2();
+
+ ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, Rule.class);
+
+ List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
+
+ if (clauseEntry1 instanceof HigherOrderClauseEntry) {
+ arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
+ } else if (clauseEntry1 instanceof NodeClauseEntry) {
+ arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ if (clauseEntry2 instanceof HigherOrderClauseEntry) {
+ arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
+ } else if (clauseEntry2 instanceof NodeClauseEntry) {
+ arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ java.util.List<Node> nodes = new ArrayList<Node>();
+
+ nodes.add(arg1Node);
+ nodes.add(arg2Node);
+ nodes.add(resultNode);
+
+ return (T) new Functor("strConcat", nodes, new BuiltinRegistry());
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/CreateLabelAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/CreateLabelAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/CreateLabelAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/CreateLabelAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+
+/**
+ *
+ * TODO
+ *
+ * @author anuzzolese
+ *
+ */
+public class CreateLabelAtom extends AbstractAdaptableAtom {
+
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DatavaluedPropertyAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DatavaluedPropertyAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DatavaluedPropertyAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DatavaluedPropertyAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.IObjectAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.TriplePattern;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts a DatavaluedPropertyAtom to triple pattern of Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class DatavaluedPropertyAtom extends AbstractAdaptableAtom {
+
+ @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 = (ClauseEntry) adapter.adaptTo(argument2, Rule.class);
+ ClauseEntry argument1ClauseEntry = (ClauseEntry) adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry datatypePropertyClauseEntry = (ClauseEntry) 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);
+ }
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DifferentAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DifferentAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DifferentAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DifferentAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.ExpressionAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Functor;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts any DifferentAtom to a notEqual functor in Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class DifferentAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ Node arg1Node = null;
+ Node arg2Node = null;
+
+ org.apache.stanbol.rules.manager.atoms.DifferentAtom tmp = (org.apache.stanbol.rules.manager.atoms.DifferentAtom) ruleAtom;
+
+ ExpressionAtom argument1 = tmp.getStringFunctionAtom1();
+ ExpressionAtom argument2 = tmp.getStringFunctionAtom2();
+
+ ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, Rule.class);
+
+ List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
+
+ if (clauseEntry1 instanceof HigherOrderClauseEntry) {
+ arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
+ } else if (clauseEntry1 instanceof NodeClauseEntry) {
+ arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ if (clauseEntry2 instanceof HigherOrderClauseEntry) {
+ arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
+ } else if (clauseEntry2 instanceof NodeClauseEntry) {
+ arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ java.util.List<Node> nodes = new ArrayList<Node>();
+
+ nodes.add(arg1Node);
+ nodes.add(arg2Node);
+
+ return (T) new Functor("notEqual", nodes, new BuiltinRegistry());
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DivisionAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DivisionAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DivisionAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/DivisionAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Functor;
+import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts any DivisionAtom to a quotient functor in Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class DivisionAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ String div_result = "div_result" + System.currentTimeMillis();
+
+ Node arg1Node = null;
+ Node arg2Node = null;
+ Node arg3Node = Node_RuleVariable.createVariable(div_result);
+
+ org.apache.stanbol.rules.manager.atoms.DivisionAtom tmp = (org.apache.stanbol.rules.manager.atoms.DivisionAtom) ruleAtom;
+
+ NumericFunctionAtom numericFunctionAtom1 = tmp.getNumericFunctionAtom1();
+ NumericFunctionAtom numericFunctionAtom2 = tmp.getNumericFunctionAtom2();
+
+ ClauseEntry clauseEntry1 = adapter.adaptTo(numericFunctionAtom1, Rule.class);
+ ClauseEntry clauseEntry2 = adapter.adaptTo(numericFunctionAtom2, Rule.class);
+
+ List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
+
+ if (clauseEntry1 instanceof HigherOrderClauseEntry) {
+ arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
+ } else if (clauseEntry1 instanceof NodeClauseEntry) {
+ arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ if (clauseEntry2 instanceof HigherOrderClauseEntry) {
+ arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
+ } else if (clauseEntry2 instanceof NodeClauseEntry) {
+ arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ java.util.List<Node> nodes = new ArrayList<Node>();
+
+ nodes.add(arg1Node);
+ nodes.add(arg2Node);
+ nodes.add(arg3Node);
+
+ ClauseEntry clauseEntry = new Functor("quotient", nodes, new BuiltinRegistry());
+
+ clauseEntries.add(clauseEntry);
+
+ return (T) new HigherOrderClauseEntry(arg3Node, clauseEntries);
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/EndsWithAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/EndsWithAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/EndsWithAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/EndsWithAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.ExpressionAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.impl.LiteralLabel;
+import com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Functor;
+import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts any EndsWithAtom to a regex functor in Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class EndsWithAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ Node arg1Node = null;
+ Node arg2Node = null;
+
+ org.apache.stanbol.rules.manager.atoms.EndsWithAtom tmp = (org.apache.stanbol.rules.manager.atoms.EndsWithAtom) ruleAtom;
+
+ ExpressionAtom argument = tmp.getArgument();
+ ExpressionAtom term = tmp.getTerm();
+
+ ClauseEntry clauseEntry1 = adapter.adaptTo(argument, Rule.class);
+ ClauseEntry clauseEntry2 = adapter.adaptTo(term, Rule.class);
+
+ List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
+
+ if (clauseEntry1 instanceof HigherOrderClauseEntry) {
+ arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
+ } else if (clauseEntry1 instanceof NodeClauseEntry) {
+ arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ if (clauseEntry2 instanceof HigherOrderClauseEntry) {
+ arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
+ } else if (clauseEntry2 instanceof NodeClauseEntry) {
+ Node tmpNode = ((NodeClauseEntry) clauseEntry2).getNode();
+ LiteralLabel literalLabel = tmpNode.getLiteral();
+ String lexicalForm = literalLabel.getLexicalForm();
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(lexicalForm);
+ sb.append("$");
+
+ String regex = sb.toString();
+
+ arg2Node = Node_RuleVariable.createLiteral(regex);
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ java.util.List<Node> nodes = new ArrayList<Node>();
+
+ nodes.add(arg1Node);
+ nodes.add(arg2Node);
+
+ return (T) new Functor("regex", nodes, new BuiltinRegistry());
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterEqualThanAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterEqualThanAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterEqualThanAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterEqualThanAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.ExpressionAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Functor;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts a GreaterEqualThanAtom to the ge functor of Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class GreaterEqualThanAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ Node arg1Node = null;
+ Node arg2Node = null;
+
+ org.apache.stanbol.rules.manager.atoms.GreaterEqualThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.GreaterEqualThanAtom) ruleAtom;
+
+ ExpressionAtom argument1 = tmp.getArgument1();
+ ExpressionAtom argument2 = tmp.getArgument2();
+
+ ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, Rule.class);
+
+ List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
+
+ if (clauseEntry1 instanceof HigherOrderClauseEntry) {
+ arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
+ } else if (clauseEntry1 instanceof NodeClauseEntry) {
+ arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ if (clauseEntry2 instanceof HigherOrderClauseEntry) {
+ arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
+ } else if (clauseEntry2 instanceof NodeClauseEntry) {
+ arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ List<Node> nodes = new ArrayList<Node>();
+
+ nodes.add(arg1Node);
+ nodes.add(arg2Node);
+
+ Functor functor = new Functor("ge", nodes, new BuiltinRegistry());
+
+ clauseEntries.add(functor);
+
+ return (T) new HigherOrderClauseEntry(arg1Node, clauseEntries);
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterThanAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterThanAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterThanAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/GreaterThanAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.ExpressionAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Functor;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts a GreaterThanAtom to the greaterThan functor of Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class GreaterThanAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ Node arg1Node = null;
+ Node arg2Node = null;
+
+ org.apache.stanbol.rules.manager.atoms.GreaterThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.GreaterThanAtom) ruleAtom;
+
+ ExpressionAtom argument1 = tmp.getArgument1();
+ ExpressionAtom argument2 = tmp.getArgument2();
+
+ ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, Rule.class);
+
+ List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
+
+ if (clauseEntry1 instanceof HigherOrderClauseEntry) {
+ arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
+ } else if (clauseEntry1 instanceof NodeClauseEntry) {
+ arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ if (clauseEntry2 instanceof HigherOrderClauseEntry) {
+ arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
+ } else if (clauseEntry2 instanceof NodeClauseEntry) {
+ arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ java.util.List<Node> nodes = new ArrayList<Node>();
+
+ nodes.add(arg1Node);
+ nodes.add(arg2Node);
+
+ Functor functor = new Functor("greaterThan", nodes, new BuiltinRegistry());
+
+ clauseEntries.add(functor);
+
+ return (T) new HigherOrderClauseEntry(arg1Node, clauseEntries);
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IndividualPropertyAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IndividualPropertyAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IndividualPropertyAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IndividualPropertyAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.IObjectAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.TriplePattern;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts a IndividualPropertyAtom to triple pattern of Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class IndividualPropertyAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom) ruleAtom;
+
+ IObjectAtom argument1 = tmp.getArgument1();
+ IObjectAtom argument2 = tmp.getArgument2();
+ IObjectAtom objectProperty = tmp.getObjectProperty();
+
+ ClauseEntry argument2ClauseEntry = (ClauseEntry) adapter.adaptTo(argument2, Rule.class);
+ ClauseEntry argument1ClauseEntry = (ClauseEntry) adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry objectPropertyClauseEntry = (ClauseEntry) adapter.adaptTo(objectProperty, Rule.class);
+
+ Node subjectNode;
+ Node predicateNode;
+ Node objectNode;
+
+ if (argument1ClauseEntry instanceof NodeClauseEntry) {
+ subjectNode = ((NodeClauseEntry) argument1ClauseEntry).getNode();
+ } else {
+ throw new RuleAtomCallExeption(getClass());
+ }
+
+ if (objectPropertyClauseEntry instanceof NodeClauseEntry) {
+ predicateNode = ((NodeClauseEntry) objectPropertyClauseEntry).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);
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IsBlankAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IsBlankAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IsBlankAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/IsBlankAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import java.util.ArrayList;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.IObjectAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Functor;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts a IsBlankAtom to the isBNode functor of Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class IsBlankAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ org.apache.stanbol.rules.manager.atoms.IsBlankAtom tmp = (org.apache.stanbol.rules.manager.atoms.IsBlankAtom) ruleAtom;
+
+ IObjectAtom uriResource = tmp.getUriResource();
+
+ ClauseEntry argumentClauseEntry = (ClauseEntry) adapter.adaptTo(uriResource, Rule.class);
+
+ Node argNode;
+
+ if (argumentClauseEntry instanceof NodeClauseEntry) {
+ argNode = ((NodeClauseEntry) argumentClauseEntry).getNode();
+ } else {
+ throw new RuleAtomCallExeption(getClass());
+ }
+
+ java.util.List<Node> nodes = new ArrayList<Node>();
+
+ nodes.add(argNode);
+
+ return (T) new Functor("isBNode", nodes, new BuiltinRegistry());
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LengthAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LengthAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LengthAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LengthAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+
+/**
+ *
+ * TODO
+ *
+ * @author anuzzolese
+ *
+ */
+public class LengthAtom extends AbstractAdaptableAtom {
+
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessEqualThanAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessEqualThanAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessEqualThanAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessEqualThanAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.ExpressionAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Functor;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts a LessEqualThanAtom to the le functor of Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class LessEqualThanAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ Node arg1Node = null;
+ Node arg2Node = null;
+
+ org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessEqualThanAtom) ruleAtom;
+
+ ExpressionAtom argument1 = tmp.getArgument1();
+ ExpressionAtom argument2 = tmp.getArgument2();
+
+ ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, Rule.class);
+
+ List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
+
+ if (clauseEntry1 instanceof HigherOrderClauseEntry) {
+ arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
+ } else if (clauseEntry1 instanceof NodeClauseEntry) {
+ arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ if (clauseEntry2 instanceof HigherOrderClauseEntry) {
+ arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
+ } else if (clauseEntry2 instanceof NodeClauseEntry) {
+ arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ java.util.List<Node> nodes = new ArrayList<Node>();
+
+ nodes.add(arg1Node);
+ nodes.add(arg2Node);
+
+ Functor functor = new Functor("le", nodes, new BuiltinRegistry());
+
+ clauseEntries.add(functor);
+
+ return (T) new HigherOrderClauseEntry(arg1Node, clauseEntries);
+
+ }
+
+}
Added: incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessThanAtom.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessThanAtom.java?rev=1306329&view=auto
==============================================================================
--- incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessThanAtom.java (added)
+++ incubator/stanbol/trunk/rules/adapters/src/main/java/org/apache/stanbol/rules/adapters/jena/atoms/LessThanAtom.java Wed Mar 28 13:55:24 2012
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stanbol.rules.adapters.jena.atoms;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.stanbol.rules.adapters.AbstractAdaptableAtom;
+import org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry;
+import org.apache.stanbol.rules.adapters.jena.NodeClauseEntry;
+import org.apache.stanbol.rules.base.api.RuleAtom;
+import org.apache.stanbol.rules.base.api.RuleAtomCallExeption;
+import org.apache.stanbol.rules.base.api.UnavailableRuleObjectException;
+import org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException;
+import org.apache.stanbol.rules.manager.atoms.ExpressionAtom;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.reasoner.rulesys.BuiltinRegistry;
+import com.hp.hpl.jena.reasoner.rulesys.ClauseEntry;
+import com.hp.hpl.jena.reasoner.rulesys.Functor;
+import com.hp.hpl.jena.reasoner.rulesys.Rule;
+
+/**
+ *
+ * It adapts a LessThanAtom to the lessThan functor of Jena.
+ *
+ * @author anuzzolese
+ *
+ */
+public class LessThanAtom extends AbstractAdaptableAtom {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption,
+ UnavailableRuleObjectException,
+ UnsupportedTypeForExportException {
+
+ Node arg1Node = null;
+ Node arg2Node = null;
+
+ org.apache.stanbol.rules.manager.atoms.LessThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessThanAtom) ruleAtom;
+
+ ExpressionAtom argument1 = tmp.getArgument1();
+ ExpressionAtom argument2 = tmp.getArgument2();
+
+ ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
+ ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, Rule.class);
+
+ List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
+
+ if (clauseEntry1 instanceof HigherOrderClauseEntry) {
+ arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
+ } else if (clauseEntry1 instanceof NodeClauseEntry) {
+ arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ if (clauseEntry2 instanceof HigherOrderClauseEntry) {
+ arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
+
+ clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
+ } else if (clauseEntry2 instanceof NodeClauseEntry) {
+ arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
+ } else {
+ throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
+ }
+
+ java.util.List<Node> nodes = new ArrayList<Node>();
+
+ nodes.add(arg1Node);
+ nodes.add(arg2Node);
+
+ Functor functor = new Functor("lessThan", nodes, new BuiltinRegistry());
+
+ clauseEntries.add(functor);
+
+ return (T) new HigherOrderClauseEntry(arg1Node, clauseEntries);
+
+ }
+
+}