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:58:49 UTC
svn commit: r1141667 -
/incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/AltStyles.scala
Author: reto
Date: Thu Jun 30 18:58:49 2011
New Revision: 1141667
URL: http://svn.apache.org/viewvc?rev=1141667&view=rev
Log:
CLEREZZA-510: splitting things to different files as a first refactoring step
Added:
incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/AltStyles.scala
Added: incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/AltStyles.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/AltStyles.scala?rev=1141667&view=auto
==============================================================================
--- incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/AltStyles.scala (added)
+++ incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/AltStyles.scala Thu Jun 30 18:58:49 2011
@@ -0,0 +1,226 @@
+/*
+ * 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.clerezza.rdf.scala.utils
+
+import java.math.BigInteger
+import java.lang.Boolean
+import java.net.{URL, URI}
+import org.apache.clerezza.rdf.ontologies.{XSD, RDF}
+import java.util.Date
+import collection.mutable.{ListBuffer, HashMap}
+import org.apache.clerezza.rdf.utils.{GraphNode, UnionMGraph}
+import org.apache.clerezza.rdf.core._
+import org.apache.clerezza.rdf.core.impl._
+
+/**
+ * Alternative method names for some RichGraphNode methods allowing alternative
+ * DSL syntaxes
+ */
+class AltStyles {
+
+}
+
+/**
+ * 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)
+ }
+
+
+}
+
+
+
+/**
+ * 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)
+
+ }
+
+
+}
+
+/**
+ * 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)
+
+ }
+
+}
\ No newline at end of file