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/06 16:03:40 UTC
svn commit: r1143419 - in /incubator/clerezza/trunk/parent:
platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/
platform.security.foafssl/test/src/main/scala/org/apache/clerezz...
Author: reto
Date: Wed Jul 6 14:03:39 2011
New Revision: 1143419
URL: http://svn.apache.org/viewvc?rev=1143419&view=rev
Log:
CLEREZZA-510: A miminum and integrated solution leaving the different style variants (with implicit arguments) to a possible new issue (after face to face discussion with Henry), adapted AccountControlPanel and WebId-testsuite for compatibility (without endorsing the code)
Removed:
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Lang.scala
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/EzMGraphTest.scala
Modified:
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/FoafBrowser.scala
incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
incubator/clerezza/trunk/parent/rdf.scala.utils/ (props changed)
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzMGraph.scala
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala
incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
Modified: incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/FoafBrowser.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/FoafBrowser.scala?rev=1143419&r1=1143418&r2=1143419&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/FoafBrowser.scala (original)
+++ incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/FoafBrowser.scala Wed Jul 6 14:03:39 2011
@@ -32,7 +32,7 @@ import java.security.{PrivilegedAction,
import org.apache.clerezza.rdf.core._
import access.TcManager
import impl.SimpleMGraph
-import org.apache.clerezza.rdf.scala.utils.{EzStyleChoice, EzMGraph}
+import org.apache.clerezza.rdf.scala.utils.EzMGraph
object FoafBrowser {
def removeHash(uri: UriRef) = {
@@ -52,9 +52,8 @@ object FoafBrowser {
*/
@Path("/browse")
class FoafBrowser extends Logging {
- import org.apache.clerezza.rdf.scala.utils.EzMGraph._
+ import org.apache.clerezza.rdf.scala.utils.Preamble._
import org.apache.clerezza.platform.accountcontrolpanel.FoafBrowser._
- import EzStyleChoice.unicode
protected def activate(componentContext: ComponentContext): Unit = {
// this.componentContext = componentContext
@@ -80,19 +79,20 @@ class FoafBrowser extends Logging {
val inference = new EzMGraph(new UnionMGraph(new SimpleMGraph(),profile))
+ import inference._
//add a bit of inferencing for persons, until we have some reasoning
for (kn: Triple <- profile.filter(null,FOAF.knows,null)) {
- inference.addType(kn.getSubject, FOAF.Person)
+ kn.getSubject a FOAF.Person
if (kn.getObject.isInstanceOf[NonLiteral])
- inference.addType(kn.getSubject,FOAF.Person)
+ kn.getObject a FOAF.Person
}
//todo: if possible get a bit more info about remote profiles, if these are in the db
//Here we make a BNode the subject of the properties as a workaround to CLEREZZA-447
- return ( inference.node(uriInfo.getRequestUri()) â PLATFORM.HeadedPage
- â CONTROLPANEL.ProfileViewerPage
- â FOAF.primaryTopic ⶠuri )
+ return ( (URItoUriRef(uriInfo.getRequestUri()) a PLATFORM.HeadedPage
+ a CONTROLPANEL.ProfileViewerPage)
+ -- FOAF.primaryTopic --> uri)
}
protected var tcManager: TcManager = null;
Modified: incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala?rev=1143419&r1=1143418&r2=1143419&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala (original)
+++ incubator/clerezza/trunk/parent/platform.accountcontrolpanel/platform.accountcontrolpanel.core/src/main/scala/org/apache/clerezza/platform/accountcontrolpanel/ProfilePanel.scala Wed Jul 6 14:03:39 2011
@@ -82,8 +82,7 @@ object ProfilePanel {
class ProfilePanel extends Logging {
import collection.JavaConversions._
- import EzMGraph._
- import EzStyleChoice.unicode
+ import Preamble._
@GET
@@ -96,36 +95,33 @@ class ProfilePanel extends Logging {
}
//todo: there is a bit of repetition in the graphs, and it is not clear why these relations should not go straight into the DB. What should, what should not?
- private def getPersonalProfile(userName: String, info: UriInfo): EzGraphNode = {
+ private def getPersonalProfile(userName: String, info: UriInfo): GraphNode = {
val profileDocUri = getSuggestedPPDUri(userName)
- val profile = AccessController.doPrivileged(new PrivilegedAction[EzGraphNodeU] {
- def run: EzGraphNodeU = {
+ val profile = AccessController.doPrivileged(new PrivilegedAction[GraphNode] {
+ def run: GraphNode = {
val userInSysGraph = userManager.getUserInSystemGraph(userName)
val user = userInSysGraph.getNode
- val profile = userInSysGraph.getNode match {
+ val profile: GraphNode = userInSysGraph.getNode match {
case blank: BNode => {
//user does not have a webId yet
- val g = EzMGraph()
- (
- g.bnode â CONTROLPANEL.isLocalProfile ⶠtrue
- â CONTROLPANEL.suggestedPPDUri ⶠprofileDocUri
- â FOAF.primaryTopic ⶠ(g.bnode â PLATFORM.userName ⶠuserName)
- )
+ val g = new EzMGraph()
+ import g._
+ val profile = bnode
+ (profile -- CONTROLPANEL.isLocalProfile --> bool2lit(true)
+ -- CONTROLPANEL.suggestedPPDUri --> profileDocUri
+ -- FOAF.primaryTopic --> (bnode -- PLATFORM.userName --> userName))
+ profile
}
case webid: UriRef => {
var webIDInfo = webIdGraphsService.getWebIdInfo(webid)
- var res = EzGraphNode(profileDocUri, new UnionMGraph(new SimpleMGraph, webIDInfo.localPublicUserData))
- (res â CONTROLPANEL.isLocalProfile ⶠwebIDInfo.isLocal
- â FOAF.primaryTopic ⶠwebid)
- if (webIDInfo.isLocal) {
- //the reason we need to call pingCollUri is we need a full URI because lack of support for relative URIs
- res â PINGBACK.to ⶠnew UriRef(PingBack.pingCollUri(userName, info))
- }
+ var res = new GraphNode(profileDocUri, new UnionMGraph(new SimpleMGraph, webIDInfo.localPublicUserData))
+ (res -- CONTROLPANEL.isLocalProfile --> bool2lit(webIDInfo.isLocal)
+ -- FOAF.primaryTopic --> webid)
res
}
}
- val friendInfo = for (kn: Triple <- profile.getGraph.filter(user.asInstanceOf[NonLiteral], FOAF.knows, null)
+ val friendInfo:Iterator[TripleCollection] = for (kn: Triple <- profile.getGraph.filter(user.asInstanceOf[NonLiteral], FOAF.knows, null)
if kn.getObject.isInstanceOf[UriRef];
friend = kn.getObject.asInstanceOf[UriRef]
if (friend != profileDocUri)
@@ -136,18 +132,21 @@ class ProfilePanel extends Logging {
} catch {
case e => {
logger.warn("cought exception trying to fetch graph - these graphs should already be in store " + friend, e)
- EzMGraph().add(friend, SKOS.note, "problem with fetching this node: " + e)
+ new EzMGraph() {
+ friend -- SKOS.note --> ("problem with fetching this node: " + e)
+ }
}
}
}
- for (g <- friendInfo) profile.graph.addAll(g)
+ //vera bad: mixing data from different sources
+ for (g <- friendInfo) profile.getGraph.addAll(g)
profile
}
})
- (profile â PLATFORM.HeadedPage
- â CONTROLPANEL.ProfilePage)
+ (profile a PLATFORM.HeadedPage
+ a CONTROLPANEL.ProfilePage)
}
/**
@@ -289,14 +288,16 @@ class ProfilePanel extends Logging {
val webIdInfo = webIdGraphsService.getWebIdInfo(webidRef);
if (webIdInfo.isLocal)
) {
- val certNode = new EzMGraph(webIdInfo.localPublicUserData).bnode
- ( certNode â RSA.RSAPublicKey
- â CERT.identity ⶠwebidRef
- â RSA.modulus ⶠmodulus
- â RSA.public_exponent ⶠpublicExponent
- â DC.date ⶠcert.getStartDate )
+ val certGraph = new EzMGraph(webIdInfo.localPublicUserData)
+ import certGraph._
+ val certNode = certGraph.bnode
+ ( (certNode a RSA.RSAPublicKey)
+ -- CERT.identity --> webidRef
+ -- RSA.modulus --> modulus
+ -- RSA.public_exponent --> publicExponent
+ -- DC.date --> cert.getStartDate )
if (comment != null && comment.length > 0) {
- certNode â RDFS.comment ⶠcomment
+ certNode -- RDFS.comment --> comment
}
}
var resBuild: Response.ResponseBuilder = Response.ok(ser.getContent, MediaType.valueOf(ser.getMimeType))
Modified: incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala?rev=1143419&r1=1143418&r2=1143419&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala (original)
+++ incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala Wed Jul 6 14:03:39 2011
@@ -36,14 +36,13 @@ import java.util.Date
import org.apache.clerezza.rdf.scala.utils.Preamble.{toRichGraphNode,toFirstElement}
import serializedform.Serializer
import java.io.ByteArrayOutputStream
-import org.apache.clerezza.rdf.scala.utils.EzMGraph._
+import org.apache.clerezza.rdf.scala.utils.Preamble._
import java.math.BigInteger
import collection.mutable.{Queue, LinkedList}
import javax.security.auth.Subject
import collection.JavaConversions._
import org.apache.clerezza.platform.users.WebIdGraphsService
import org.apache.clerezza.rdf.scala.utils._
-import EzStyleChoice.arrow
/**
* implementation of (very early) version of test server for WebID so that the following tests
@@ -129,6 +128,7 @@ class CertTester(subj: Subject, webIdGra
def runTests() {
+ import g._
val thisDoc = (g.bnode.a(FOAF.Document) //there really has to be a way to get THIS doc url, to add relative urls to the graph
-- DCTERMS.created --> now
)
@@ -146,7 +146,7 @@ class CertTester(subj: Subject, webIdGra
// Assertion public key
//
val pubkey = claim.cert.getPublicKey
- val testCertKey = create(TEST.certificatePubkeyRecognised, cert.ref)
+ val testCertKey = create(TEST.certificatePubkeyRecognised, cert)
pubkey match {
case rsa: RSAPublicKey => {
@@ -158,7 +158,7 @@ class CertTester(subj: Subject, webIdGra
val res = testCertKey.result;
res.description = "Certificate contains RSA key which is recognised"
res.outcome = EARL.passed
- res.pointer(pk.ref)
+ res.pointer(pk.getNode.asInstanceOf[NonLiteral])
}
case _ => {
testCertKey.result.description = "Certificate contains key that is not understood by WebID layer " +
@@ -170,7 +170,7 @@ class CertTester(subj: Subject, webIdGra
//
// Assertion time stamp of certificate
//
- val dateOkAss = create(TEST.certificateDateOk, cert.ref)
+ val dateOkAss = create(TEST.certificateDateOk, cert)
val notBefore = claim.cert.getNotBefore
val notAfter = claim.cert.getNotAfter
@@ -178,12 +178,12 @@ class CertTester(subj: Subject, webIdGra
dateOkAss.result("Certificate time is too early. Watch out this is often due to time " +
"synchronisation issues accross servers", failed)
} else if (now.after(notAfter)) {
- dateOkAss.result("Certificate validity time has expired. ", failed, thisDoc.ref)
+ dateOkAss.result("Certificate validity time has expired. ", failed, thisDoc.getNode)
} else {
- dateOkAss.result("Certificate time is valid", passed, thisDoc.ref)
+ dateOkAss.result("Certificate time is valid", passed, thisDoc.getNode)
}
- cert.ref -> claim
+ cert -> claim
}
//
@@ -600,15 +600,16 @@ class CertTester(subj: Subject, webIdGra
sout.serialize(out, graph, "text/rdf+n3")
val n3String = out.toString("UTF-8")
//todo: turtle mime type literal?
- val keylit: EzGraphNode = g.bnode -- OWL.sameAs --> (n3String^^"http://example.com/turtle".uri)
+ import g._
+ val keylit: GraphNode = g.bnode -- OWL.sameAs --> (n3String^^"http://example.com/turtle".uri)
//
// some of the tester we will complete here
//
- val asrtKeyModulusFunc = create(TEST.pubkeyRSAModulusFunctional, keylit.ref)
- val asrtKeyExpoFunc = create(TEST.pubkeyRSAExponentFunctional, keylit.ref)
- val asrtWffkey = create(TEST.profileWellFormedKey, keylit.ref)
+ val asrtKeyModulusFunc = create(TEST.pubkeyRSAModulusFunctional, keylit.getNode)
+ val asrtKeyExpoFunc = create(TEST.pubkeyRSAExponentFunctional, keylit.getNode)
+ val asrtWffkey = create(TEST.profileWellFormedKey, keylit.getNode)
var claimsTobeRsaKey = pkey.hasProperty(RDF.`type`, RSA.RSAPublicKey)
@@ -637,7 +638,7 @@ class CertTester(subj: Subject, webIdGra
} else {
asrtKeyModulusFunc.result("Found one Modulus", passed)
- rsaModOk = testRSAModulus(mods, keylit.ref)
+ rsaModOk = testRSAModulus(mods, keylit.getNode)
}
if (exps.size == 0) {
@@ -653,7 +654,7 @@ class CertTester(subj: Subject, webIdGra
//we could have a problem
} else {
asrtKeyExpoFunc.result("Found one Modulus", passed)
- rsaExpOk = testRSAExp(mods, keylit.ref)
+ rsaExpOk = testRSAExp(mods, keylit.getNode)
}
if (rsaExpOk && rsaModOk) {
@@ -706,7 +707,8 @@ class Assertor {
new TstResult
}
- def toRdf(): EzGraphNode = (
+ import g._
+ def toRdf(): GraphNode = (
g.bnode.a(EARL.Assertion)
-- EARL.test --> testName
-- EARL.result --> result.toRdf()
@@ -738,13 +740,15 @@ class Assertor {
}
- def toRdf(): EzGraphNode = (
- g.bnode.a(EARL.TestResult)
+ def toRdf(): GraphNode = {
+ import g._
+ (g.bnode.a(EARL.TestResult)
-- DC.description --> description
-- EARL.outcome --> outcome
-- EARL.pointer -->> pointers
-- EARL.info -->> { for (e <- exceptions) yield new PlainLiteralImpl(e.toString) }
- )
+ )
+ }
}
Propchange: incubator/clerezza/trunk/parent/rdf.scala.utils/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 6 14:03:39 2011
@@ -1 +1,2 @@
/incubator/clerezza/issues/CLEREZZA-29/org.apache.clerezza.rdf.scala.utils:891751-892221
+/incubator/clerezza/issues/CLEREZZA-510-reto/rdf.scala.utils:1141555-1143359
Modified: incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzMGraph.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzMGraph.scala?rev=1143419&r1=1143418&r2=1143419&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzMGraph.scala (original)
+++ incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/EzMGraph.scala Wed Jul 6 14:03:39 2011
@@ -19,110 +19,21 @@
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 impl._
+import org.apache.clerezza.rdf.core.impl._
+import scala.collection.mutable.HashMap
-object EzMGraph {
-
- def apply(graph: TripleCollection) = new EzMGraph(graph)
- def apply() = new EzMGraph()
-
- private val litFactory = LiteralFactory.getInstance
-
- implicit def string2lit(str: String) = new EzLiteral(str)
-
- implicit def lit2String(lit: Literal) = lit.getLexicalForm
-
- implicit def date2lit(date: Date) = litFactory.createTypedLiteral(date)
-
- implicit def int2lit(int: Int) = litFactory.createTypedLiteral(int)
-
- implicit def bigint2lit(bint: BigInt) = litFactory.createTypedLiteral(bint.underlying())
-
- implicit def bigint2lit(bigInt: BigInteger) = litFactory.createTypedLiteral(bigInt)
-
- implicit def bool2lit(boolean: Boolean) = litFactory.createTypedLiteral(boolean)
-
- implicit def scalaBool2lit(boolean: scala.Boolean) = litFactory.createTypedLiteral(boolean)
-
- implicit def long2lit(long: Long) = litFactory.createTypedLiteral(long)
-
- implicit def double2lit(double: Double) = litFactory.createTypedLiteral(double)
-
- implicit def uriRef2Prefix(uriRef: UriRef) = new NameSpace(uriRef.getUnicodeString)
-
- implicit def URItoUriRef(uri: URI) = new UriRef(uri.toString)
-
- implicit def URLtoUriRef(url: URL) = new UriRef(url.toExternalForm)
-
- //inspired from http://programming-scala.labs.oreilly.com/ch11.html
-
-}
/**
- * An easy Literal implementations, contains functions for mapping literals to other literals, ie from String literals to
- * typed literals.
- */
-class EzLiteral(lexicalForm: String) extends TypedLiteralImpl(lexicalForm,XSD.string) {
-
- /**
- * @return a plain literal with language specified by lang
- */
- def lang(lang: Lang) = new PlainLiteralImpl(lexicalForm, lang)
- def lang(lang: Symbol) = new PlainLiteralImpl(lexicalForm, new Language(lang.name)) //todo lookup in LangId instead
-
- /**
- * Map to a Typed Literal of given type
- */
- def ^^(typ: UriRef) = new TypedLiteralImpl(lexicalForm, typ)
-
- /**
- * Map to a URI of given lexical form
- */
- def uri = new UriRef(lexicalForm)
-
-}
-
-/**
- * A way to select one's preferred writing style
- */
-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)
- }
-
-
-}
-/**
- * EzMGraph enhances graph writing. Used together with EzGraphNode, it can make writing rdf graphs in code a lot more
+ * EzMGraph enhances graph writing, it can make writing rdf graphs in code a lot more
* readable, as it avoids a lot of repetition.
*
- * @param graph: a Triple collection - or should it be an MGraph since it is really meant to be modifiable
- * @author hjs
+ * @param graph: a Triple collection
+ * @author hjs, reto
* @created: 20/04/2011
*/
-//todo: should this take a TripleCollection or a Set[Triple]
-class EzMGraph(val baseTc: TripleCollection) extends AbstractMGraph {
+class EzMGraph(val baseTc: MGraph) extends AbstractMGraph with TcDependentConversions {
+
def this() = this (new SimpleMGraph())
@@ -141,429 +52,28 @@ class EzMGraph(val baseTc: TripleCollect
}
/**
- * create a new bnode based EzGraphNode with the preferred writing style
+ * create a new bnode
*/
- def bnode[T<: EzGraphNode](implicit writingStyle: EzStyle[T]=EzStyleChoice.arrow ): T = {
- node(new BNode)(writingStyle)
+ def bnode: BNode = {
+ new BNode
}
- protected val namedBnodes = new HashMap[String,BNode]
+ private val namedBnodes = new HashMap[String,BNode]
/**
* create a new named bnode based EzGraphNode with the preferred writing style
*/
- def b_[T<: EzGraphNode](name: String)(implicit writingStyle: EzStyle[T]=EzStyleChoice.arrow): T = {
+ def b_(name: String): BNode = {
namedBnodes.get(name) match {
- case Some(bnode) => writingStyle.preferred(bnode,baseTc)
+ case Some(bnode) => bnode
case None => {
val bn = new BNode
namedBnodes.put(name, bn);
- writingStyle.preferred(bn,baseTc)
+ bn
}
}
}
- /**
- * create a new url based EzGraphNode with the preferred writing style
- */
- def u[T<: EzGraphNode](url: String)(implicit writingStyle: EzStyle[T]=EzStyleChoice.arrow): T = {
- node(new UriRef(url))(writingStyle)
- }
-
- /**
- * create a new Resource based EzGraphNode with the preferred writing style.
- * The EzGraphNode will contain the graph that this EzMGraph is built on and point to the given subj
- */
- def node[T<: EzGraphNode](subj: NonLiteral)(implicit writingStyle: EzStyle[T]=EzStyleChoice.arrow ): T = {
- writingStyle.preferred(subj,baseTc)
- }
-
- /**
- * Add a a relation
- * @param subj: subject of relation
- * @param relation: relation
- * @param: obj: the object of the statement
- * @return this, to making method chaining easier
- */
- def add(subj: NonLiteral, relation: UriRef, obj: Resource ) = {
- baseTc.add(new TripleImpl(subj,relation,obj))
- baseTc
- }
-
- /**
- * Add a type relation for the subject
- * @param subj: the subject of the relation
- * @param clazz: the rdfs:Class the subject is an instance of
- * @return this, to making method chaining easier
- */
- def addType(subj: NonLiteral, clazz: UriRef) = {
- baseTc.add(new TripleImpl(subj,RDF.`type`,clazz))
- baseTc
- }
-
-
}
-/**
- * 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 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 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:
- *
- * <blockquote>
- The precedence of an infix operator is determined by the operatorâs first character.
- Characters are listed below in increasing order of precedence, with characters on
- the same line having the same precedence.
- (all letters)
- |
- ^
- &
- < >
- = !
- :
- + -
- * / %
- (all other special characters)
-
- That is, operators starting with a letter have lowest precedence, followed by operators
- starting with â|â, etc.
- Thereâs one exception to this rule, which concerns assignment operators(§6.12.4).
- The precedence of an assigment operator is the same as the one of simple assignment
- (=). That is, it is lower than the precedence of any other operator.
- The associativity of an operator is determined by the operatorâs last character. Operators
- ending in a colon â:â are right-associative. All other operators are leftassociative.
- </blockquote>
- */
-class EzGraphNodeA(ref: NonLiteral, graph: TripleCollection) extends EzGraphNode(ref, graph) {
-
- type T_Pred = PredicateA
- type T_InvP = InversePredicateA
- type T_EzGN = EzGraphNodeA
-
- override protected def make(ref: NonLiteral, graph: TripleCollection) = new EzGraphNodeA(ref,graph)
- override protected def predicate(rel: UriRef) = new PredicateA(rel)
- override protected def inverse(rel: UriRef) = new InversePredicateA(rel)
-
- /**
- * relate the subject via the given relation to....
- */
- def --(rel: UriRef) = predicate(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) = inverse(rel)
-
- class PredicateA(rel: UriRef) extends Predicate(rel) {
- /**
- * ...to the following non resource
- */
- def -->(obj: Resource) = add(obj)
-
- /**
- * Adds a relation to a real linked list.
- * If you want one relation to each entry use -->> or â¶*
- */
- def -->(list: List[Resource]) = addList(list)
-
- /**
- * ...to the EzGraphNode, which is useful for opening a parenthesis.
- */
- def -->(sub: EzGraphNode) = addEG(sub)
-
- /**
- * Add one relation for each member of the iterable collection
- */
- def -->>[T <: Resource](uris: Iterable[T]) = addMany(uris)
-
-
- }
-
- class InversePredicateA(ref: UriRef) extends InversePredicate(ref) {
- /**
- * ...to the following non literal
- */
- def --(subj: NonLiteral) = add(subj)
-
- /**
- * ...to the following EzGraphNode
- * (useful for opening a new parenthesis and specifying other things in more detail
- */
- def --(subj: EzGraphNode) = addGN(subj)
- // since we can only have inverses from non literals (howto deal with bndoes?)
- }
-
-}
-
-/**
- * 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 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 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 EzMGraph object. Differnt notations implementations can be used.
- */
-abstract class EzGraphNode(val ref: NonLiteral, val graph: TripleCollection) extends RichGraphNode(ref, graph) {
-
-// lazy val easyGraph = graph match {
-// case eg: EzMGraph => eg
-// case other: TripleCollection => new EzMGraph(graph)
-// }
-
- def +(sub: EzGraphNode) = {
- if (graph ne sub.graph) graph.addAll(sub.graph)
- this
- }
-
- type T_Pred <: Predicate
- type T_InvP <: InversePredicate
- type T_EzGN <: EzGraphNode
-
- protected def predicate(rel: UriRef): T_Pred
- protected def inverse(rel: UriRef): T_InvP
- protected def make(ref: NonLiteral, graph: TripleCollection): T_EzGN
-
- /** is an instance of the given class */
- def a(rdfclass: UriRef): T_EzGN = {
- graph.add(new TripleImpl(ref, RDF.`type`, rdfclass))
- return this.asInstanceOf[T_EzGN]
- }
-
- /*
- * create an EzGraphNode from this one where the backing graph is protected from writes by a new
- * SimpleGraph.
- */
- def protect(): T_EzGN = make(ref, new UnionMGraph(new SimpleMGraph(), graph))
-
- def this(s: NonLiteral) = this (s, new SimpleMGraph())
-
- def this() = this (new BNode)
-
- /** class for Inverse relations with the current EzGraphNode.ref as object */
- abstract class InversePredicate(rel: UriRef) {
-
- protected def addGN(subj: EzGraphNode) = {
- EzGraphNode.this + subj
- add(subj.ref)
- }
-
- protected def add(subj: NonLiteral) = {
- graph.add(new TripleImpl(subj, rel, ref))
- EzGraphNode.this.asInstanceOf[T_EzGN]
- }
- }
-
- /**
- * class for relations with the current EzGraphNode.ref as subject
- */
- abstract class Predicate(rel: UriRef) {
-
- protected def add(obj: Resource): T_EzGN = {
- addTriple(obj)
- EzGraphNode.this.asInstanceOf[T_EzGN]
- }
-
- protected def addTriple(obj: Resource) {
- graph.add(new TripleImpl(ref, rel, obj))
- }
-
- protected def addMany[T<:Resource](uris: Iterable[T]): T_EzGN = {
- for (u <- uris) addTriple(u)
- EzGraphNode.this.asInstanceOf[T_EzGN]
- }
-
- protected def addEG(sub: EzGraphNode): T_EzGN = {
- EzGraphNode.this + sub
- add(sub.ref)
- }
-
- private def toTriples[T <: Resource](head: NonLiteral,list : List[T]): List[Triple] = {
- val answer = new ListBuffer[Triple]
- var varList = list
- var headRef = head
- while (varList != Nil) {
- varList = varList match {
- case head :: next :: rest => {
- val nextRef = new BNode
- answer.append(new TripleImpl(headRef, RDF.first, head))
- answer.append(new TripleImpl(headRef, RDF.rest, nextRef))
- headRef = nextRef
- next :: rest
- }
- case head :: Nil => {
- answer.append(new TripleImpl(headRef, RDF.first, head))
- answer.append(new TripleImpl(headRef, RDF.rest, RDF.nil))
- Nil
- }
- case Nil => Nil
- }
- }
- answer.toList
- }
-
-
- protected def addList[T <: Resource](list: List[T]) = {
- val headNode = new BNode
- addTriple(headNode)
- val tripleLst = toTriples(headNode,list);
- graph.add(new TripleImpl(headNode,RDF.`type`,RDF.List))
- graph.addAll(collection.JavaConversions.asJavaCollection(tripleLst))
- EzGraphNode.this.asInstanceOf[T_EzGN]
- }
-
- }
-
-}
Modified: incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala?rev=1143419&r1=1143418&r2=1143419&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala (original)
+++ incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/Preamble.scala Wed Jul 6 14:03:39 2011
@@ -58,7 +58,13 @@ object Preamble extends TcIndependentCon
*
* @author hjs, reto
*/
-class Preamble(baseTc: TripleCollection) extends TcIndependentConversions {
+class Preamble(val baseTc: TripleCollection) extends TcDependentConversions {
+
+}
+protected trait TcDependentConversions extends TcIndependentConversions {
+
+ def baseTc: TripleCollection
+
implicit def toRichGraphNode(resource: Resource) = {
new RichGraphNode(new GraphNode(resource, baseTc))
}
@@ -124,14 +130,23 @@ protected object TcIndependentConversion
*/
class LiteralBuilder(val lexicalForm: String) {
- /**
+ /**
* Produces a PlainLiteral with the wrapped String as lexical form
* and a given language
*
* @param lang the language tag of the literal to be created
* @return a plain literal with the specified language
*/
- def lang(lang: Lang) = new PlainLiteralImpl(lexicalForm, lang)
+ def lang(lang: Language) = new PlainLiteralImpl(lexicalForm, lang)
+
+ /**
+ * Produces a PlainLiteral with the wrapped String as lexical form
+ * and a given language
+ *
+ * @param lang a sthe language tag of the literal to be created as String
+ * @return a plain literal with the specified language
+ */
+ def lang(lang: String) = new PlainLiteralImpl(lexicalForm, new Language(lang))
/**
* Produces a PlainLiteral with the wrapped String as lexical form
Modified: incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala?rev=1143419&r1=1143418&r2=1143419&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala (original)
+++ incubator/clerezza/trunk/parent/rdf.scala.utils/src/main/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNode.scala Wed Jul 6 14:03:39 2011
@@ -18,11 +18,14 @@
*/
package org.apache.clerezza.rdf.scala.utils
+import org.apache.clerezza.rdf.ontologies.RDF
import org.apache.clerezza.rdf.utils.GraphNode
import java.util.Iterator
import _root_.scala.collection.JavaConversions._
import _root_.scala.reflect.Manifest
-import org.apache.clerezza.rdf.core.{TripleCollection, UriRef, Resource, Literal, TypedLiteral, LiteralFactory}
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph
+import org.apache.clerezza.rdf.core.{TripleCollection, UriRef, Resource, Literal, TypedLiteral, LiteralFactory, NonLiteral, BNode}
+import org.apache.clerezza.rdf.utils.UnionMGraph
/**
@@ -42,7 +45,7 @@ class RichGraphNode(resource: Resource,
* @param node The GraphNode to be wrapped
*/
def this(node: GraphNode) = this(node.getNode, node.getGraph)
-
+
/**
* Operator syntax shortcut to get all objects as <code>RichGraphNode</code>
*
@@ -134,6 +137,104 @@ class RichGraphNode(resource: Resource,
base.remove()
}
}
+
+ /**
+ *Sets the RDF:type of the subject */
+ def a(rdfclass: UriRef): RichGraphNode = {
+ addProperty(RDF.`type`, rdfclass)
+ return this
+ }
+
+ /*
+ * create an RichGraphNode from this one where the backing graph is protected from writes by a new
+ * SimpleGraph.
+ */
+ def protect(): RichGraphNode = new RichGraphNode(getNode, new UnionMGraph(new SimpleMGraph(), graph))
+
+
+ /**
+ * relate the subject via the given relation to....
+ */
+ def --(rel: Resource): DashTuple = new DashTuple(rel)
+
+ def --(rel: RichGraphNode): DashTuple = new DashTuple(rel.getNode)
+
+
+ /**
+ * relate the subject via the inverse of the given relation to....
+ */
+ 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 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 DashTuple(val second: Resource) {
+
+ val first = RichGraphNode.this
+ /**
+ * ...to the following non resource
+ */
+ def -->(obj: Resource): RichGraphNode = {
+ val property = second match {
+ case u: UriRef => u;
+ case _ => throw new RuntimeException("Property must be a UriRef")
+ }
+ RichGraphNode.this.addProperty(property, obj)
+ RichGraphNode.this
+ }
+
+
+ /**
+ * ...to the EzGraphNode, which is useful for opening a parenthesis.
+ */
+ def -->(sub: GraphNode): RichGraphNode = {
+ //RichGraphNode.this + sub
+ -->(sub.getNode)
+ }
+ /**
+ * Add one relation for each member of the iterable collection
+ */
+ def -->>[T <: Resource](uris: Iterable[T]): RichGraphNode = {
+ for (u <- uris) -->(u)
+ RichGraphNode.this
+ }
+ }
}
Modified: incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala?rev=1143419&r1=1143418&r2=1143419&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala (original)
+++ incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/RichGraphNodeTest.scala Wed Jul 6 14:03:39 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"))
Modified: incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala?rev=1143419&r1=1143418&r2=1143419&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala (original)
+++ incubator/clerezza/trunk/parent/rdf.scala.utils/src/test/scala/org/apache/clerezza/rdf/scala/utils/TypeConversionTest.scala Wed Jul 6 14:03:39 2011
@@ -43,9 +43,8 @@ class TypeConversionTest {
@Test
def useStringWithLanguageTag {
- import org.apache.clerezza.rdf.scala.utils.Lang._
val lit = new PlainLiteralImpl("a value", new Language("en"))
- val t = new TripleImpl(new UriRef(("http://example.org/subject")), new UriRef(("http://example.org/predicate")), "a value" lang en)
+ val t = new TripleImpl(new UriRef(("http://example.org/subject")), new UriRef(("http://example.org/predicate")), "a value" lang "en")
val t2 = new TripleImpl(new UriRef(("http://example.org/subject")), new UriRef(("http://example.org/predicate")), "a value" lang 'en)
Assert.assertEquals(lit, t.getObject)
Assert.assertEquals(lit, t2.getObject)