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/06/30 20:56:41 UTC

svn commit: r1141666 - /incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala

Author: reto
Date: Thu Jun 30 18:56:40 2011
New Revision: 1141666

URL: http://svn.apache.org/viewvc?rev=1141666&view=rev
Log:
CLEREZZA-510: splitting things to different files as a first refactoring step

Modified:
    incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala

Modified: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.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/EzGraph.scala?rev=1141666&r1=1141665&r2=1141666&view=diff
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala (original)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzGraph.scala Thu Jun 30 18:56:40 2011
@@ -43,22 +43,7 @@ abstract class EzStyle[T<:EzGraphNode]()
 	def preferred(ref: NonLiteral, tc: TripleCollection):T
 }
 
-/**
- * import your preferred writing styles into your code
- */
-object EzStyleChoice {
-	implicit val unicode = new EzStyle[EzGraphNodeU](){
-		override def preferred(ref: NonLiteral, tc: TripleCollection): EzGraphNodeU = new EzGraphNodeU(ref,tc)
-	}
-	implicit val arrow = new EzStyle[EzGraphNodeA](){
-		override def preferred(ref: NonLiteral, tc: TripleCollection): EzGraphNodeA = new EzGraphNodeA(ref,tc)
-	}
-   implicit val english = new EzStyle[EzGraphNodeEn](){
-		override def preferred(ref: NonLiteral, tc: TripleCollection): EzGraphNodeEn = new EzGraphNodeEn(ref,tc)
-	}
-
 
-}
 /**
  * EzGraph enhances graph writing. Used together with EzGraphNode, it can make writing rdf graphs in code a lot more
  * readable, as it avoids a lot of repetition.
@@ -149,98 +134,6 @@ class EzGraph(val baseTc: MGraph) extend
 }
 
 /**
- * Unicode arrow notation for EzGraphNode. Very clean, short and efficient, but unicode values may not
- * be available everywhere yet.
- *
- * Because of operator binding rules all the mathematical operators  bind the strongest. This means that
- * anything outside of these operators should be put into brackets or use dot notation if you wish them to
- * bind more tightly.
- *
- *
- * @prefix graph: should this be an MGraph, since the EzGraphNode is really designed for editing
- *
- */
-class EzGraphNodeU(ref: NonLiteral, graph: TripleCollection) extends EzGraphNode(ref, graph) {
-	//
-	// symbolic notation
-	//
-	// (shorter and more predictable precedence rules, but unicode issues)
-
-	type T_Pred = PredicateU
-	type T_InvP = InversePredicateU
-	type T_EzGN = EzGraphNodeU
-
-	override def make(ref: NonLiteral, graph: TripleCollection) = new EzGraphNodeU(ref,graph)
-	override def predicate(rel: UriRef) = new PredicateU(rel)
-	override def inverse(rel: UriRef) = new InversePredicateU(rel)
-
-	/**
-	 * relate the subject via the given relation to....
-	 */
-	def ⟝(rel: UriRef) = predicate(rel)
-
-	/**
-	 * relate the subject via the given relation to....
-	 */
-	def ⟝(rel: String) = predicate(new UriRef(rel))
-
-	/**
-	 * relate the subject via the inverse of the given relation to....
-	 */
-	def ⟵(rel: UriRef) = inverse(rel)
-
-	/**
-	 * the subject is a member of the given class
-	 */
-	def ∈(rdfclass: UriRef) = a(rdfclass)
-
-
-	class InversePredicateU(rel: UriRef) extends InversePredicate(rel) {
-		/**
-		 * ...to the following non literal
-		 */
-		def ⟞(subj: NonLiteral) = add(subj)
-
-		/**
-		 * ...to the following resource (given as a string)
-		 */
-		def ⟞(uri: String) = add(new UriRef(uri))
-
-		/**
-		 * ...to the following EzGraphNode
-		 * (useful for opening a new parenthesis and specifying other things in more detail
-		 */
-		def ⟞(sub: EzGraphNodeU)  = addGN(sub)
-	}
-
-	class PredicateU(rel: UriRef) extends Predicate(rel) {
-
-		/**
-		 * ...to the following resource
-		 */
-		def ⟶(obj: Resource) = add(obj)
-
-		/**
-		 * ...to the following list as an RDF List
-		 */
-		def ⟶(list: List[Resource]) = addList(list)
-
-		/**
-		 * Add one relation for each member of the iterable collection
-		 */
-		def ⟶*[T <: Resource](objs: Iterable[T]) = addMany(objs)
-
-		/**
-		 * ...to the EzGraphNode, which is useful for opening a parenthesis.
-		 */
-		def ⟶(sub: EzGraphNode) = addEG(sub)
-
-	}
-
-
-}
-
-/**
  * Ascii Arrow notation for EzGraphNode. This is easy to write using an ascii keyboard but because
  * of operator precedence rules, some operators will have higher and some lower precedence to these
  * meaning that one has to keep in mind these rules:
@@ -341,106 +234,24 @@ class EzGraphNodeA(ref: NonLiteral, grap
 
 }
 
-/**
- * English language looking Notation for EzGraphNode. This feels gives somewhat awkward
- * english, but the operator binding priorities for ascii named operators is the weakest, which
- * means that one needs very few parenthesis when writing out the code as all other operators bind
- * more tightly.
- */
-class EzGraphNodeEn(ref: NonLiteral, graph: TripleCollection) extends EzGraphNode(ref, graph) {
-
-	type T_Pred = PredicateEn
-	type T_InvP = InversePredicateEn
-	type T_EzGN = EzGraphNodeEn
-
-	override protected def make(ref: NonLiteral, graph: TripleCollection) = new EzGraphNodeEn(ref,graph)
-	override protected def predicate(rel: UriRef) = new PredicateEn(rel)
-	override protected def inverse(rel: UriRef) = new InversePredicateEn(rel)
-
-	/**
-	 * the subject has the given relation to....
-	 */
-	def has(rel: UriRef) = predicate(rel)
-
-	/**
-	 * the subject has the given relation (specified as string) to....
-	 */
-	def has(rel: String) = predicate(new UriRef(rel))
-
-	/**
-	 * the subject is the inverse relation of ...
-	 */
-	def is(rel: UriRef) = inverse(rel)
-
-	class InversePredicateEn(rel: UriRef) extends InversePredicate(rel) {
-
-
-		/**
-		  * ...the following non literal
-		  */
-		def of(subj: NonLiteral) = add(subj)
-
-		/**
-		  * ...the following resource (as String)
-		  */
-		def of(subj: String) = add(new UriRef(subj))
-
-		/**
-		  * ...the following EzGraphNode - useful for opening a new bracket
-		  */
-		def of(subj: EzGraphNode) = addGN(subj)
-	}
-
-	class PredicateEn(rel: UriRef) extends Predicate(rel) {
-
-
-		/**
-		 * ...to the following resource
-		 */
-		def to(obj: Resource) = add(obj)
-
-		/**
-		 * ...to the following RDF list
-		 */
-		def to(list: List[Resource]) = addList(list)
-
-		/**
-		 * ... each of the members of the iterable collection
-		 */
-		def toEach[T <: Resource](objs: Iterable[T]) = addMany(objs)
-
-		/**
-		 * ...to the EzGraphNode, which is useful for opening a parenthesis.
-		 */
-		def to(sub: EzGraphNode) = addEG(sub)
-
-	}
-
-}
-
-object EzGraphNode {
-	/**
-	 * create a new EzGraphNode in the preferred writing style
-	 */
-	def apply[T<:EzGraphNode](ref: NonLiteral, graph: TripleCollection)(implicit writingStyle: EzStyle[T]=EzStyleChoice.arrow ): T = {
-	 	writingStyle.preferred(ref,graph)
-	}
-}
 
 /**
  * EzGraphNode. Create instances from an EzGraph object. Differnt notations implementations can be used.
  */
-abstract class EzGraphNode(val ref: NonLiteral, val graph: TripleCollection) extends GraphNode(ref, graph) {
+abstract class EzGraphNode(val ref: NonLiteral, val graph: TripleCollection) extends RichGraphNode(ref, graph) {
 
 //	lazy val easyGraph = graph match {
 //		case eg: EzGraph => eg
 //		case other: TripleCollection => new EzGraph(graph)
 //	}
 
-	def +(sub: EzGraphNode) = {
+	//removed this as:
+	// + is typically a symmatric operation, which it isn't here
+	// we should use a unin-mgraph rather than copying around triples
+	/*def +(sub: EzGraphNode) = {
 		if (graph ne sub.graph) graph.addAll(sub.graph)
 		this
-	}
+	}*/
 
 	type T_Pred <: Predicate
 	type T_InvP <: InversePredicate
@@ -470,7 +281,7 @@ abstract class EzGraphNode(val ref: NonL
 	abstract class InversePredicate(rel: UriRef) {
 
 		protected def addGN(subj: EzGraphNode) = {
-			EzGraphNode.this + subj
+			//EzGraphNode.this + subj
 			add(subj.ref)
 		}
 
@@ -500,7 +311,7 @@ abstract class EzGraphNode(val ref: NonL
 		}
 
 		protected def addEG(sub: EzGraphNode): T_EzGN = {
-			EzGraphNode.this + sub
+			//EzGraphNode.this + sub
 			add(sub.ref)
 		}
 
@@ -542,3 +353,12 @@ abstract class EzGraphNode(val ref: NonL
 
 }
 
+object EzGraphNode {
+	/**
+	 * create a new EzGraphNode in the preferred writing style
+	 */
+	def apply[T<:EzGraphNode](ref: NonLiteral, graph: TripleCollection)(implicit writingStyle: EzStyle[T]=EzStyleChoice.arrow ): T = {
+	 	writingStyle.preferred(ref,graph)
+	}
+}
+