You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2011/07/01 17:24:07 UTC

svn commit: r1141963 - in /incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src: main/scala/org/apache/clerezza/rdf/scala/utils/ test/scala/org/apache/clerezza/rdf/scala/utils/

Author: reto
Date: Fri Jul  1 15:24:06 2011
New Revision: 1141963

URL: http://svn.apache.org/viewvc?rev=1141963&view=rev
Log:
CLEREZZA-510: using <-- instead of -<- for inverse properties

Modified:
    incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
    incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
    incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala

Modified: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala?rev=1141963&r1=1141962&r2=1141963&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala (original)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala Fri Jul  1 15:24:06 2011
@@ -155,57 +155,67 @@ class RichGraphNode(resource: Resource, 
 	/**
 	 * relate the subject via the given relation to....
 	 */
-	def --(rel: UriRef): Predicate = new Predicate(rel)
+	def --(rel: Resource): DashTuple = new DashTuple(rel)
+
+	def --(rel: RichGraphNode): DashTuple = new DashTuple(rel.getNode)
 
-	/**
-	 * relate the subject via the given (expressed as string) relation to....
-	 */
-	def --(rel: String): Predicate = --(new UriRef(rel))
 
 	/**
 	 * relate the subject via the inverse of the given relation to....
-	 * note: we can't have <-- as that messes up the balance of precedence
 	 */
-	def -<-(rel: UriRef) = new InversePredicate(rel)
+	def <--(tuple: RichGraphNode#DashTuple): RichGraphNode = {
+		val inversePropertyRes = tuple.first.getNode
+		val inverseProperty: UriRef =  inversePropertyRes match {
+			case p: UriRef => p
+			case _ => throw new RuntimeException("DashTuple must be a UriRef")
+		}
+		RichGraphNode.this.addInverseProperty(inverseProperty, tuple.second)
+		RichGraphNode.this
+	}
 
 
 	/** class for Inverse relations with the current RichGraphNode.ref as object */
 	//TODO add support for adding many for symmetry reasons
-	class InversePredicate(rel: UriRef) {
-
-		/**
-		 * ...to the following non literal
-		 */
-		def --(subj: NonLiteral): RichGraphNode = {
-			RichGraphNode.this.addInverseProperty(rel, subj)
-			RichGraphNode.this
-		}
-		
-		/**
-		 * ...to the following resource (given as a string)
-		 */
-		def --(subj: String): RichGraphNode = --(new UriRef(subj))
-
-		/**
-		 * ...to the following EzGraphNode
-		 * (useful for opening a new parenthesis and specifying other things in more detail
-		 */
-		def --(subj: GraphNode): RichGraphNode = {
-			--(subj.getNode.asInstanceOf[NonLiteral])
-		}
-		// since we can only have inverses from non literals (howto deal with bndoes?)
-	}
+//	class InverseDashTuple(rel: DashTuple) {
+//
+//		/**
+//		 * ...to the following non literal
+//		 */
+//		def --(subj: NonLiteral): RichGraphNode = {
+//			RichGraphNode.this.addInverseProperty(rel, subj)
+//			RichGraphNode.this
+//		}
+//
+//		/**
+//		 * ...to the following resource (given as a string)
+//		 */
+//		def --(subj: String): RichGraphNode = --(new UriRef(subj))
+//
+//		/**
+//		 * ...to the following EzGraphNode
+//		 * (useful for opening a new parenthesis and specifying other things in more detail
+//		 */
+//		def --(subj: GraphNode): RichGraphNode = {
+//			--(subj.getNode.asInstanceOf[NonLiteral])
+//		}
+//		// since we can only have inverses from non literals (howto deal with bndoes?)
+//	}
 
 	/**
 	 *  class for relations with the current RichGraphNode.ref as subject
 	 */
-	class Predicate(rel: UriRef) {
+	class DashTuple(val second: Resource) {
 
+		val first = RichGraphNode.this
 		/**
 		 * ...to the following non resource
 		 */
 		def -->(obj: Resource): RichGraphNode = {
-			RichGraphNode.this.addProperty(rel, obj)
+			val property = second match {
+				case u: UriRef => u;
+				case _ => throw new RuntimeException("Property must be a UriRef")
+			}
+			RichGraphNode.this.addProperty(property, obj)
 			RichGraphNode.this
 		}
 

Modified: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala?rev=1141963&r1=1141962&r2=1141963&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala (original)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzGraphTest.scala Fri Jul  1 15:24:06 2011
@@ -95,6 +95,19 @@ class EzGraphTest {
 		Assert.assertEquals("The two graphs should be equals", expected, ez.getGraph)
 	}
 
+	@Test
+	def inverseTriple {
+		val expected = {
+			val s = new SimpleMGraph
+			s.add(new TripleImpl(retoUri.uri, FOAF.knows, henryUri.uri))
+			s.getGraph
+		}
+		val ez = new EzMGraph() {
+			henryUri.uri <--  FOAF.knows -- retoUri.uri
+		}
+		Assert.assertEquals("The two graphs should be equals", expected, ez.getGraph)
+	}
+
 //	@Test
 //	def simpleGraphEquality {
 //		val gr = new SimpleMGraph
@@ -281,12 +294,13 @@ class EzGraphTest {
 			 "http://bblfish.net/#hjs".uri.a(FOAF.Person)
 				  -- FOAF.name --> "Henry Story"
 				  -- FOAF.currentProject --> "http://webid.info/".uri
-				  -<- identity -- (
+				  -- FOAF.knows -->> List(b_("reto"), b_("danny"))
+				  //one need to list properties before inverse properties, or use brackets
+				  <-- identity -- (
 						   bnode.a(RSAPublicKey) //. notation because of precedence of operators
 							   -- modulus --> 65537
 							   -- public_exponent --> (bblfishModulus^^hex) // brackets needed due to precedence
-						   )
-				  -- FOAF.knows -->> List(b_("reto"), b_("danny"))
+						   )  
 			) --
 			FOAF.knows --> (b_("danny").a(FOAF.Person) --
 							   FOAF.name --> "Danny Ayers".lang('en)

Modified: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala?rev=1141963&r1=1141962&r2=1141963&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala (original)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala Fri Jul  1 15:24:06 2011
@@ -41,11 +41,13 @@ class RichGraphNodeTest {
 		mGraph.add(new TripleImpl(johnUri, FOAF.nick, new PlainLiteralImpl("johny")));
 		mGraph.add(new TripleImpl(johnUri, FOAF.name, new PlainLiteralImpl("Johnathan Guller")));
 		mGraph.add(new TripleImpl(johnUri, FOAF.knows, billBNode))
+		mGraph.add(new TripleImpl(johnUri, RDF.`type`, FOAF.Person));
 		mGraph.add(new TripleImpl(billBNode, FOAF.nick, new PlainLiteralImpl("Bill")));
 		mGraph.add(new TripleImpl(billBNode, FOAF.name, new PlainLiteralImpl("William")));
 		mGraph.add(new TripleImpl(billBNode, RDF.`type`, FOAF.Person));
 		mGraph.add(new TripleImpl(susanneUri, FOAF.knows, johnUri));
 		mGraph.add(new TripleImpl(susanneUri, FOAF.name, new PlainLiteralImpl("Susanne")));
+		mGraph.add(new TripleImpl(susanneUri, RDF.`type`, FOAF.Person));
 		val rdfList = new RdfList(listUri, mGraph);
 		rdfList.add(johnUri)
 		rdfList.add(new PlainLiteralImpl("foo"))