[z3-checkins] r9771 - in z3/zemantic/branch/tseaver-distutils_reorg: . browser lib src src/zemantic src/zemantic/browser src/zemantic/lib src/zemantic/tests tests

tseaver at codespeak.net tseaver at codespeak.net
Mon Mar 14 18:51:10 MET 2005


Author: tseaver
Date: Mon Mar 14 18:51:09 2005
New Revision: 9771

Added:
   z3/zemantic/branch/tseaver-distutils_reorg/src/
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/__init__.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/__init__.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/browser/
      - copied from r9770, z3/zemantic/branch/tseaver-distutils_reorg/browser/
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/cataloger.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/cataloger.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/configure.zcml
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/configure.zcml
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/events.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/events.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/expressions.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/expressions.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/informationstore.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/informationstore.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/interfaces.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/interfaces.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/lib/
      - copied from r9770, z3/zemantic/branch/tseaver-distutils_reorg/lib/
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/public.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/public.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/query.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/query.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/resources.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/resources.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/result.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/result.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/tests/
      - copied from r9770, z3/zemantic/branch/tseaver-distutils_reorg/tests/
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/triplestore.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/triplestore.py
   z3/zemantic/branch/tseaver-distutils_reorg/src/zemantic/utils.py
      - copied unchanged from r9770, z3/zemantic/branch/tseaver-distutils_reorg/utils.py
Removed:
   z3/zemantic/branch/tseaver-distutils_reorg/__init__.py
   z3/zemantic/branch/tseaver-distutils_reorg/browser/
   z3/zemantic/branch/tseaver-distutils_reorg/cataloger.py
   z3/zemantic/branch/tseaver-distutils_reorg/configure.zcml
   z3/zemantic/branch/tseaver-distutils_reorg/events.py
   z3/zemantic/branch/tseaver-distutils_reorg/expressions.py
   z3/zemantic/branch/tseaver-distutils_reorg/informationstore.py
   z3/zemantic/branch/tseaver-distutils_reorg/interfaces.py
   z3/zemantic/branch/tseaver-distutils_reorg/lib/
   z3/zemantic/branch/tseaver-distutils_reorg/public.py
   z3/zemantic/branch/tseaver-distutils_reorg/query.py
   z3/zemantic/branch/tseaver-distutils_reorg/resources.py
   z3/zemantic/branch/tseaver-distutils_reorg/result.py
   z3/zemantic/branch/tseaver-distutils_reorg/tests/
   z3/zemantic/branch/tseaver-distutils_reorg/triplestore.py
   z3/zemantic/branch/tseaver-distutils_reorg/utils.py
Log:
Move pacakge files down into 'src/zemantic' to make distutils easier.

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/__init__.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/__init__.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,25 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-# Handy query constants and classes
-
-Any = None
-
-from rdflib.URIRef import URIRef
-from rdflib.BNode import BNode
-from rdflib.Literal import Literal
-
-from query import Query, UnionChain, IntersectionChain
-
-from expressions import ZemanticExpr

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/cataloger.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/cataloger.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,84 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier 
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-
-__rdf_description__ = '''\
-<rdf:RDF xmlns="http://web.resource.org/cc/"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
-<Work rdf:about="http://zemantic.org/zemantic/cataloger.py"
-  dc:title="zemantic.cataloger"
-  dc:date="2005"
-  dc:description="Sample auto-cataloging code.  See examples/library/cataloger.py.">
-    <dc:creator>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:creator>
-    <dc:rights>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:rights>
-    <license rdf:resource="http://zemantic.org/LICENSE.txt/"/>
-</Work>
-</rdf:RDF>
-'''
-
-from zope.app import zapi
-from zope.app.container.interfaces import IObjectAddedEvent
-from zope.app.container.interfaces import IObjectRemovedEvent
-from zope.app.event.interfaces import IObjectModifiedEvent
-from interfaces import IRDFXML, ITripleStore
-
-from StringIO import StringIO
-
-# This is an example cataloger that hooks Zope 3 container events.
-# Your application should create their own catalogers for their
-# content types so that they can exactly control cataloging.  See
-# examples/library/cataloger.py
-
-class Cataloger(object):
-    """Class to handle automatic cataloging/uncataloging on container
-    events."""
-
-    def __init__(self, iface):
-        self._iface = iface
-
-    def __call__(self, event):
-        """Called by the event system."""
-        if self._iface.providedBy(event.object):
-            
-            if IObjectAddedEvent.providedBy(event):
-                self.handleAdded(event.object)
-                
-            elif IObjectModifiedEvent.providedBy(event):
-                self.handleModified(event.object)
-                
-            elif IObjectRemovedEvent.providedBy(event):
-                self.handleRemoved(event.object)
-
-    def handleAdded(self, object):
-        c = zapi.queryUtility(ITripleStore)
-        if c is not None:
-            pass # add your logic here
-    
-    def handleModified(self, object):
-        c = zapi.queryUtility(ITripleStore)
-        if c is not None:
-            pass # add your logic here
-
-    def handleRemoved(self, object):
-        c = zapi.queryUtility(ITripleStore)
-        if c is not None:
-            pass # add your logic here
-
-
-cataloger = Cataloger(ITripleStore)

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/configure.zcml
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/configure.zcml	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,92 +0,0 @@
-<configure
-  xmlns="http://namespaces.zope.org/zope"
-  xmlns:browser="http://namespaces.zope.org/browser"
-  i18n_domain="zemantic">
-
-  <content class=".triplestore.TripleStore">
-    <implements interface="zope.app.annotation.IAttributeAnnotatable" />
-    <implements interface="zope.app.utility.interfaces.ILocalUtility" />
-    <allow interface=".interfaces.ITripleStore" />
-  </content>
-
-  <content class=".informationstore.InformationStore">
-    <implements interface="zope.app.annotation.IAttributeAnnotatable" />
-    <implements interface="zope.app.utility.interfaces.ILocalUtility" />
-    <allow interface=".interfaces.IInformationStore" />
-  </content>
-
-  <module module="rdflib.BNode">
-    <allow attributes="BNode" />
-  </module>
-
-  <module module="rdflib.URIRef">
-    <allow attributes="URIRef" />
-  </module>
-
-  <module module="rdflib.Literal">
-    <allow attributes="Literal" />
-  </module>
-
-  <module module="rdflib.Identifier">
-    <allow attributes="Identifier" />
-  </module>
-
-  <content class="rdflib.BNode.BNode">
-    <implements interface=".interfaces.IIdentifier" />
-    <allow interface=".interfaces.IIdentifier" />
-  </content>
-
-
-  <content class="rdflib.URIRef.URIRef">
-    <implements interface=".interfaces.IIdentifier" />
-    <allow interface=".interfaces.IIdentifier" />
-  </content>
-
-  <content class="rdflib.Literal.Literal">
-    <implements interface=".interfaces.IIdentifier" />
-    <allow interface=".interfaces.IIdentifier" />
-  </content>
-
-  <content class="rdflib.Identifier.Identifier">
-    <implements interface=".interfaces.IIdentifier" />
-    <allow interface=".interfaces.IIdentifier" />
-  </content>
-
-
-  <content class=".result.Result">
-    <implements interface=".interfaces.IResult" />
-    <allow interface=".interfaces.IResult" />
-  </content>
-
-  <content class=".query.Query">
-    <implements interface=".interfaces.IQuery" />
-    <allow interface=".interfaces.IQuery" />
-  </content>
-
-  <content class=".query.UnionChain">
-    <implements interface=".interfaces.IQueryChain" />
-    <allow interface=".interfaces.IQueryChain" />
-  </content>
-
-  <content class=".query.IntersectionChain">
-    <implements interface=".interfaces.IQueryChain" />
-    <allow interface=".interfaces.IQueryChain" />
-  </content>
-
-<adapter
-    factory=".triplestore.TripleStoreSized"
-    provides="zope.app.size.interfaces.ISized"
-    for=".interfaces.ITripleStore"
-    />
-
-
-<adapter
-    factory=".informationstore.InformationStore"
-    provides="zope.app.size.interfaces.ISized"
-    for=".interfaces.IInformationStore"
-    />
-
-  <include package=".browser" />
-
-</configure>
-

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/events.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/events.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,75 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-
-__rdf_description__ = '''\
-<rdf:RDF xmlns="http://web.resource.org/cc/"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
-<Work rdf:about="http://zemantic.org/zemantic/zemantic.py"
-  dc:title="zemantic.events"
-  dc:date="2005"
-  dc:description="Catalog events and default handling.">
-    <dc:creator>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:creator>
-    <dc:rights>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:rights>
-    <license rdf:resource="http://zemantic.org/LICENSE.txt/"/>
-</Work>
-</rdf:RDF>
-'''
-
-from rdflib.URIRef import URIRef
-from rdflib.BNode import BNode
-from rdflib.Literal import Literal
-from rdflib.Identifier import Identifier
-
-from query import Query
-from interfaces import IZemanticEvent, ITripleAfterAddEvent, ITripleBeforeRemoveEvent
-
-from zope.interface import implements
-from zope.interface.verify import verifyClass
-
-from zope.event import notify
-
-class ZemanticEvent(object):
-    """
-    A zemantic event.  Instanciated by zemantic catalogs when the
-    store is manipluated.
-    """
-
-    implements(IZemanticEvent)
-
-    def __init__(self, data=()):
-        self.data = data
-
-
-class TripleAfterAddEvent(ZemanticEvent):
-    
-    implements(ITripleAfterAddEvent)
-
-
-class TripleBeforeRemoveEvent(ZemanticEvent):
-    
-    implements(ITripleBeforeRemoveEvent)
-
-
-def afterAdd(data):
-    notify(TripleAfterAddEvent(data))
-
-
-def beforeRemove(data):
-    notify(TripleBeforeRemoveEvent(data))    

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/expressions.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/expressions.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,231 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-__rdf_description__ = '''\
-<rdf:RDF xmlns="http://web.resource.org/cc/"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
-<Work rdf:about="http://zemantic.org/zemantic/expressions.py"
-  dc:title="zemantic.expressions"
-  dc:date="2005"
-  dc:description="TALES Zemantic expressions.">
-    <dc:creator>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:creator>
-    <dc:rights>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:rights>
-    <license rdf:resource="http://zemantic.org/LICENSE.txt/"/>
-</Work>
-</rdf:RDF>
-'''
-
-from zope.app import zapi
-from types import UnicodeType, TupleType
-from zope.interface import implements
-from zope.security.proxy import removeSecurityProxy
-from zope.tales.tales import _valid_name, _parse_expr, NAME_RE, Undefined, CompilerError
-from zope.tales.interfaces import ITALESExpression, ITALESFunctionNamespace
-
-from rdflib.URIRef import URIRef
-from rdflib.BNode import BNode
-from rdflib.Literal import Literal
-from rdflib.Identifier import Identifier
-
-from interfaces import *
-from query import Query, UnionChain
-from result import ResultSet
-
-import sys
-from zope.tales.engine import Engine
-from zope.tales.tales import Context
-
-class ZemanticExpr(object):
-    """\
-Zemantic query expressions.
-
-  A zemantic expression has the triple expression form:
-
-    (<s expr>, <p expr>, <o expr>)
-
-  The results of each sub expression in the triple pattern are used to
-  query the nearest zemantic catalog site utility.
-
-  Sub-expressions can be any kind of TALES expression (string, nocall,
-  not, path, python etc.) but the expression must return one of the
-  following:
-
-     None - Matches all ident
-
-     string or unicode - a string or unicode identifier in N3 format.
-
-     IIdentifier implementor (BNode, URIRef, Literal) - an identifier
-     object.
-
-  Inner queries can be defined by returning:
-
-     3-tuple - defines standard inner query.
-
-     IQuery implementor - defines custom inner query.
-
-  The actual query logic is not implemented by the expression, for
-  that look at zemantic.query.Query.
-
-    """
-
-    implements(ITALESExpression)
-
-    def __init__(self, name, expr, engine):
-        self._s = expr
-        self._name = name
-        self.engine = engine
-        self.expr = self._compile(expr)
-                
-    def _compile(self, expression):
-        m = _parse_expr(expression)
-        if m:
-            type = m.group(1)
-            expr = expression[m.end():]
-        else:
-            type = "python"
-            expr = expression
-        try:
-            handler = self.engine.getTypes()[type]
-        except KeyError:
-            raise CompilerError, ('Unrecognized expression type "%s".' % type)
-        return handler(type, expr, self.engine)
-
-
-    def __call__(self, econtext):
-
-        c = zapi.queryUtility(ITripleStore)
-        o = zapi.queryUtility(IInformationStore)
-        
-        # eval each expression, stuffing the result in a Query object.
-        # Query will raise an error if the argument is not proper
-        # like.
-
-        if c is not None:
-            econtext.setLocal('zem', c)
-        if o is not None:
-            econtext.setLocal('zon', o)
-
-        econtext.setLocal('Any', None)
-        econtext.setLocal('URIRef', URIRef)
-        econtext.setLocal('BNode', BNode)
-        econtext.setLocal('Literal', Literal)
-
-        q = self.expr(econtext)
-
-        if type(q) is TupleType:
-            if len(q) != 3:
-                raise ValueError, "Zemantic expression must be a " \
-                                  "3 element tuple or provide IQuery"
-            s, p, o = q
-            q = Query(removeSecurityProxy(s),
-                      removeSecurityProxy(p),
-                      removeSecurityProxy(o))
-
-        elif not IQuery.providedBy(q):
-            raise ValueError, "Zemantic expression must be a " \
-                              "3 element tuple or provide IQuery"
-        else:
-            q = removeSecurityProxy(q)
-            
-        for result in c.query(q):
-            yield result
-
-    def __str__(self):
-        return self._s
-
-    def __repr__(self):
-        return '<ZemanticExpr %s>' % self._s
-
-
-class RDFExpr(object):
-    """\
-    Render results of a Zemantic expression into RDF XML.
-
-    """
-
-    implements(ITALESExpression)
-
-    def __init__(self, name, expr, engine):
-        self._s = expr
-        self._name = name
-        self.engine = engine
-        self.expr = self._compile(expr)
-                
-    def _compile(self, expression):
-        m = _parse_expr(expression)
-        if m:
-            type = m.group(1)
-            expr = expression[m.end():]
-        else:
-            type = "zemantic"
-            expr = expression
-        try:
-            handler = self.engine.getTypes()[type]
-        except KeyError:
-            raise CompilerError, ('Unrecognized expression type "%s".' % type)
-        return handler(type, expr, self.engine)
-
-
-    def __call__(self, econtext):
-
-        c = zapi.queryUtility(ITripleStore)
-        o = zapi.queryUtility(IInformationStore)
-        
-        if c is not None:        
-            econtext.setLocal('zem', c)
-        if o is not None:
-            econtext.setLocal('zon', o)
-
-
-        econtext.setLocal('Any', None)
-        econtext.setLocal('URIRef', URIRef)
-        econtext.setLocal('BNode', BNode)
-        econtext.setLocal('Literal', Literal)
-
-        # eval each expression, stuffing the result in a Query object.
-        # Query will raise an error if the argument is not proper
-        # like.
-        
-        return ResultSet(self.expr(econtext)).rdfxml()
-
-    def __str__(self):
-        return self._s
-
-    def __repr__(self):
-        return '<RDFExpr %s>' % self._s
-
-def eval(expr, context=None):
-    
-    c = zapi.queryUtility(ITripleStore, context=context)
-    o = zapi.queryUtility(IInformationStore, context=context)
-    
-    econtext = Context(Engine, {})
-    
-    if c is not None:        
-        econtext.setLocal('zem', c)
-    if o is not None:
-        econtext.setLocal('zon', o)
-            
-    econtext.setLocal('Any', None)
-    econtext.setLocal('URIRef', URIRef)
-    econtext.setLocal('BNode', BNode)
-    econtext.setLocal('Literal', Literal)
-    
-    bytecode = Engine.compile(expr)
-    return bytecode(econtext)

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/informationstore.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/informationstore.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,170 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-
-__rdf_description__ = '''\
-<rdf:RDF xmlns="http://web.resource.org/cc/"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
-<Work rdf:about="http://zemantic.org/zemantic/zemantic.py"
-  dc:title="zemantic.zemantic"
-  dc:date="2005"
-  dc:description="Information store catalogs.">
-    <dc:creator>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:creator>
-    <dc:rights>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:rights>
-    <license rdf:resource="http://zemantic.org/LICENSE.txt/"/>
-</Work>
-</rdf:RDF>
-'''
-from persistent import Persistent
-from persistent.dict import PersistentDict
-
-from rdflib.InformationStore import InformationStore as rdflibInformationStore     # not pickleable
-from rdflib.InformationStore import ContextBackend
-from rdflib.URIRef import URIRef
-from rdflib.BNode import BNode
-from rdflib.Literal import Literal
-from rdflib.Identifier import Identifier
-import urllib
-
-from query import Query
-from triplestore import TripleStore
-from lib.ZODBBackend import ZODBBackend
-from lib.IOZODBContextBackend import IOZODBContextBackend
-from interfaces import ITripleStore, IInformationStore, IContext
-from events import afterAdd, beforeRemove
-
-from zope.interface import implements
-from zope.interface.verify import verifyClass
-from zope.app.size.interfaces import ISized
-
-class InformationStore(Persistent):
-    """
-    A wrapper around a persistent rdflib backend that is used to
-    construct an rdflib informationstore.
-
-      >>> c = InformationStore()
-      >>> IInformationStore.providedBy(c)
-      True
-      >>> verifyClass(IInformationStore, InformationStore)
-      True
-
-    """
-
-    implements(IInformationStore)
-
-    _v_store = backend = __parent__ = __name__ = None
-    notify = False
-
-    def __init__(self, backend=None):
-        if backend is None:
-            backend = IOZODBContextBackend()
-        self.backend = backend
-
-    def clear(self):
-        """
-        Clear information store.
-        """
-        for context in self.getContexts():
-            for t in self.triples((None, None, None), context):
-                self.remove(t, context)
-
-    def notifyOn(self):
-        """
-        Turn on event notification.
-        """
-        self.notify = True
-
-    def notifyOff(self):
-        self.notify = False
-
-    def getStore(self):
-        """
-        Returns a InformationStore wrapping the semantic storage.
-        """
-        if self._v_store is None:
-            self._v_store = rdflibInformationStore(backend=self.backend)  # not pickleable
-        return self._v_store
-
-    store = property(getStore)
-
-    def parse(self, rdf, context, format="xml"):
-        """
-        Parse RDF information.  The optional"format" argument can be "xml"
-        (the default) or "nt".  Note, I have not tested nt yet.  Also a
-        bug in rdflib requires you pass a file like object.
-        """
-        self.getContext(context).parse(rdf, format=format)
-
-    def add(self, (subject, predicate, object), context):
-        """
-        Add a triple to the storage.
-        """
-        t = (subject, predicate, object)
-        self.store.add(t, context)
-
-        if self.notify:
-            afterAdd(t)
-
-    def remove(self, (subject, predicate, object), context):
-        """
-        Add a triple to the storage.
-        """
-        t = (subject, predicate, object)
-        if self.notify:
-            beforeRemove(t)
-
-        self.store.remove(t, context)
-
-    def triples(self, (subject, predicate, object), context, *args):
-        """
-        Query the triple storage.  The argument is a triple pattern
-        which can contain a valid value or None to indicate any value
-        is desired.
-        """
-        
-        for triple in  self.store.triples((subject, predicate, object), context):
-            yield triple
-
-    def query(self, q):
-        """
-        Query zemantic with a query object.
-        """
-        return q(self)
-
-    def getContext(self, context):
-        return TripleStore(backend=ContextBackend(self.store, context))
-
-    def getContexts(self):
-        for context in self.store.contexts():
-            yield self.getContext(context)
-
-    def __len__(self):
-        return len(list(self.store.contexts()))
-
-class InformationStoreSized(object):
-    implements(ISized)
-
-    def __init__(self, istore):
-        self._istore = istore
-
-    def sizeForSorting(self):
-        return ('item', len(self._istore))
-
-    def sizeForDisplay(self):
-        return str(len(self._istore)) + ' triples'

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/interfaces.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/interfaces.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,282 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-__rdf_description__ = '''\
-<rdf:RDF xmlns="http://web.resource.org/cc/"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
-<Work rdf:about="http://zemantic.org/zemantic/interfaces.py"
-  dc:title="zemantic.interfaces"
-  dc:date="2005"
-  dc:description="Interface definitions for Zemantic components.">
-    <dc:creator>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:creator>
-    <dc:rights>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:rights>
-    <license rdf:resource="http://zemantic.org/LICENSE.txt/"/>
-</Work>
-</rdf:RDF>
-'''
-
-from zope.i18nmessageid import MessageIDFactory
-from zope.interface import Interface, classImplements, Attribute, Invalid
-
-_ = MessageIDFactory('zemantic')
-
-class IRDFXML(Interface):
-    """ Interface for a component that wants to generate RDF XML."""
-
-    def xml():
-        """ Return the RDF XML description of this component. """
-
-
-class IRDAbout(Interface):
-    """ Interface for a component that wants to generate RDF XML."""
-
-    def about():
-        """ Return the RDF XML description of this component. """
-
-class IQuery(Interface):
-    
-    """ Any callable.  Returns a result set or None (no results) or
-    throws an exception. """
-
-    def __call__(store, *args):
-        """ Eval a query with given args.  Returns a result Set.
-        Queries throw QueryException to indicate failure."""
-
-
-class IQueryChain(IQuery):
-    
-    """ Abstract class to combine a "chain" of queries into one result
-    set.  QueryChains are themselves Queries, and can be nested. """
-
-
-    def add(query):
-        """ Append a query onto the chain """
-
-    def getQueries():
-        """ Return the chain of queries. """
-
-
-class IQueryable(Interface):
-    """ A generic catalog interface, there is nothing specificly in
-    this interface about zemantic or semantic web notions, it provides
-    for a query operation of any kind and could be used for other
-    forms of catalogs like a port of textindexng.  ."""
-
-    def query(query):
-        """ Query the catalog with a query object, returning a sequence of results. """
-
-class IZemanticEvent(Interface):
-    """ When triples are added or removed from the storage, these
-    events are fired.  Not sure if this interface is even necessary."""
-
-
-class ITripleAfterAddEvent(Interface):
-    """ When triples are added or removed from the storage, these
-    events are fired.  Not sure if this interface is even necessary."""
-
-
-class ITripleBeforeRemoveEvent(Interface):
-    """ When triples are added or removed from the storage, these
-    events are fired.  Not sure if this interface is even necessary."""
-
-
-class ITripleStore(IQueryable):
-    '''\
-    Semantic Web Catalog.
-
-    Zemantic "catalogs" (ie indexes) data expressed in the Resource
-    Description Framework (RDF).  Any kind of content, whether inside Zope
-    or from some outside source, can be cataloged if it can describe
-    itself using the RDF standard.  Any kind of RDF vocabulary like RSS,
-    OWL, DAML+OIL, Dublin Core, or any kind of XML schema or data can be
-    expressed into the catalog.
-
-    Once data is cataloged into Zemantic it can be queried using either
-    the Python query interface or a TALES-based RDF query expression
-    language.  Results of a query can be either a generator of result
-    records or RDF in xml or NT format.
-
-    Zemantic has two main components that are both configured as a local
-    Zope 3 site utility.  The Zemantic utility is the actual catalog of
-    meta-data and the Zontology utility is used to managed registered
-    ontologies, or schemas, such as Dublin Core, FoaF
-    (Friend-of-a-Friend), OWL, etc.
-
-    In Semantic Web terms, Zemantic is a persistent triple store.  RDF
-    is broken down into subject, predicate, and object relations
-    (called triples) and each relation is indexed.  The triple store
-    can then be queried for triples that match patterns.
-
-    A Zemantic is queried by calling its query() method with a query
-    object that provide zemantic.interfaces.IQuery.  See
-    zemantic.query.Query for an example of such an object or the
-    zemantic.expressions modules for example of query expressions.
-    
-    '''
-
-    def notifyOn():
-        """ Turn on triple add and remove notification. """
-
-    def notifyOff():
-        """ Turn off triple add and remove notification. """
-
-    def clear():
-        """ Clear the catalog.  Removes all relations. """
-
-    def getStore():
-        """ Return the catalog rdflib backend storage. """
-
-    def parse(rdf, format="xml"):
-        """ Parse RDF-XML into the catalog. """
-
-    def add((subject, predicate, object)):
-        """ Add one triple to the catalog.  """
-
-    def remove((subject, predicate, object)):
-        """ Remove one triple from the catalog. """
-
-    def triples((subject, predicate, object), *args):
-        """ Query the triple store. """
-
-    def subjects(predicate=None, object=None):
-        """ Return all subjects.  Optionally provide qualifying predicate and object. """
-        
-    def predicates(subject=None, object=None):
-        """ Return all predicates. Optionally provide qualifying subject and object. """
-
-    def objects(subject=None, predicate=None):
-        """ Return all objects.  Optionally provide qualifying subject and predicate. """
-
-    def subject_predicates(object=None):
-        """ """
-            
-    def subject_objects(predicate=None):
-        """ """
-        
-    def predicate_objects(subject=None):
-        """ """
-
-    def transitive_objects(subject, property, remember=None):
-        """ """
-
-    def transitive_subjects(predicate, object, remember=None):
-        """ """
-        
-    def uniqueSubjects():
-        """ All unique subjects. """
-
-    def uniquePredicates():
-        """ All unique predicates. """
-
-    def uniqueObjects():
-        """ All unique objects. """
-
-    def rdfxml():
-        """ Returns rdf xml representation of store. """
-
-    def rdfnt():
-        """ Returns rdf nt representation of store. """
-
-    def __len__():
-        """ Return the total number of triples in the store.  Might be
-        expensive."""
-
-
-class IContext(ITripleStore):
-
-    def __str__():
-        """ Returns context as string. """
-    
-
-class IInformationStore(IQueryable):
-    """ An rdflib-style information store. """
-
-    def notifyOn():
-        """ Turn on triple add and remove notification. """
-
-    def notifyOff():
-        """ Turn off triple add and remove notification. """
-
-    def clear():
-        """ Clear the catalog.  Removes all relations. """
-
-    def getStore():
-        """ Return the catalog rdflib backend storage. """
-
-    def parse(rdf, context, format="xml"):
-        """ Parse RDF-XML into the catalog. """
-
-    def add((subject, predicate, object), context):
-        """ Add one triple to the catalog in a given context. """
-
-    def remove((subject, predicate, object), context):
-        """ Remove one triple from the catalog in a given context.   """
-
-    def triples((subject, predicate, object), context, *args):
-        """ Query the information store. """
-
-    def getContext(context):
-        """ Return a triple store of the given context. """
-
-    def getContexts():
-        """ Return a generator of all contexts in the information store. """
-
-    def __len__():
-        """ Return number of contexts in store. """
-        
-# we have to assert all of these interfaces here so that they work with Zope 3
-
-from rdflib.URIRef import URIRef
-from rdflib.BNode import BNode
-from rdflib.Literal import Literal
-from rdflib.Identifier import Identifier
-
-class IIdentifier(Interface):
-
-    def n3():
-        """ Return N3 representation of identifier. """
-
-    def startswith(string):
-        """ dummy. """
-
-    def __cmp__(other):
-        """ dummy. """
-
-classImplements(Identifier, IIdentifier)
-classImplements(URIRef, IIdentifier)
-classImplements(BNode, IIdentifier)
-classImplements(Literal, IIdentifier)
-
-class IResult(Interface):
-    subject = Attribute("Result subject.")
-    predicate = Attribute("Result predicate.")
-    object = Attribute("Result object.")
-
-    def triple():
-        """ Return 3-tuple of result. """
-
-class IResultSet(Interface):
-
-    def rdfxml():
-        """ Return rdfxml of result set. """
-
-    def rdfnt():
-        """ Return nt format of result set. """
-    
-    

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/public.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/public.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,16 +0,0 @@
-
-Any = None
-
-from interfaces import *
-
-from rdflib.URIRef import URIRef
-from rdflib.BNode import BNode
-from rdflib.Literal import Literal
-from rdflib.Identifier import Identifier
-
-from triplestore import TripleStore
-from informationstore import InformationStore
-from query import Query
-from result import Result, ResultSet
-
-from expressions import eval

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/query.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/query.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,310 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-"""
-Queries are any callable object (like a function) that query the
-triple store.  These are technically not agents, just agent helpers.
-QueryChains are queries that chains other queries in various ways
-(union, intersection).
-
-"""
-
-__rdf_description__ = '''\
-<rdf:RDF xmlns="http://web.resource.org/cc/"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
-<Work rdf:about="http://zemantic.org/zemantic/query.py"
-  dc:title="zemantic.query"
-  dc:date="2005"
-  dc:description="Queries and stock query logic.">
-    <dc:creator>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:creator>
-    <dc:rights>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:rights>
-    <license rdf:resource="http://zemantic.org/LICENSE.txt/"/>
-</Work>
-</rdf:RDF>
-'''
-
-from types import UnicodeType, NoneType, TupleType
-from rdflib.Identifier import Identifier
-from rdflib.URIRef import URIRef
-from rdflib.BNode import BNode
-from rdflib.Literal import Literal
-
-from zope.interface import implements
-from interfaces import IQuery, IQueryChain, IIdentifier
-from result import Result
-
-import BTrees
-from BTrees.OOBTree import OOSet as Set
-
-class QueryException(Exception):
-
-    """ Thrown by a query to indicate a query exception."""
-
-class BadQueryException(QueryException):
-
-    """ Throw by a query to indicate a query is malformed."""
-
-class Query(object):
-    
-    """ A generic query logic class.  A straightforward interface to
-    zemantic.TripleStore.triples() with support for inner queries.
-
-    This class does simple triple pattern queries on a catalog.  If an
-    identifier term is a nested query (3-tuple or IQuery implementor)
-    then it performs the inner query first, applying each of the
-    results of the inner query to the outer query.
-
-    When called, returns a result generator or None (no results) or
-    throws an exception.
-
-      >>> from triplestore import TripleStore
-      >>> c = TripleStore()
-      >>> q = Query(None, None, None)
-      >>> c.query(q) is not None
-      True
-
-    """
-
-    implements(IQuery)
-
-    inner = False
-
-    def __init__(self, subject=None, predicate=None, object=None, context=None):
-        s, p, o, c = subject, predicate, object, context
-
-        ts = type(s)
-        if ts is UnicodeType:
-            if s.startswith("<"):
-                s = URIRef(s[1:-1])
-            elif s.startswith('"'):
-                raise ValueError, "Literals cannot be subjects."
-            elif s.startswith('_'):
-                s = BNode(s)
-            else:
-                raise ValueError, "Unicode subject term %s is not a well formed N3 identifier" % s
-        elif ts is TupleType or IQuery.providedBy(s):
-            self.inner = True
-        elif ts is NoneType or IIdentifier.providedBy(s):
-            pass # it's cool
-        else:
-            raise ValueError, "Subject term must be None unicode, IIdentifier, IQuery or 3-tuple."
-            
-
-        tp = type(p)
-        if tp is UnicodeType:
-            if p.startswith("<"):
-                p = URIRef(p[1:-1])
-            elif p.startswith('"'):
-                raise ValueError, "Literals cannot be predicates."
-            elif p.startswith('_'):
-                raise ValueError, "BNodes cannot be predicates."
-            else:
-                raise ValueError, "Unicode predicate term %s is not a well formed N3 identifier" % p
-        elif tp is TupleType or IQuery.providedBy(p):
-            self.inner = True
-        elif tp is NoneType or IIdentifier.providedBy(p):
-            pass # it's cool
-        else:
-            raise ValueError, "Subject term must be None unicode, IIdentifier, IQuery or 3-tuple."
-
-
-        to = type(o)
-        if to is UnicodeType:
-            if o.startswith("<"):
-                o = URIRef(o[1:-1])
-            elif o.startswith('"'):
-                o = Literal(o[1:-1])
-            elif o.startswith('_'):
-                o = BNode(o)
-            else:
-                raise ValueError, "Unicode object term %s is not a well formed N3 identifier" % o
-
-        elif to is TupleType or IQuery.providedBy(o):
-            self.inner = True
-        elif to is NoneType or IIdentifier.providedBy(o):
-            pass # it's cool
-        else:
-            raise ValueError, "Object term must be None, unicode, IIdentifier, IQuery or 3-tuple."
-
-
-        tc = type(c)
-        if tc is UnicodeType:
-            if c.startswith("<"):
-                c = URIRef(c[1:-1])
-            elif c.startswith('"'):
-                raise ValueError, "Literals cannot be contexts."
-            elif c.startswith('_'):
-                raise ValueError, "BNodes cannot be contexts."
-            else:
-                raise ValueError, "Unicode context term %s is not a well formed N3 identifier" % o
-
-        elif tc is TupleType or IQuery.providedBy(c):
-            self.inner = True
-        elif tc is NoneType or IIdentifier.providedBy(c):
-            pass # it's cool
-        else:
-            raise ValueError, "Context term must be None, unicode, IIdentifier, IQuery or 3-tuple."
-
-        self.s = s
-        self.p = p
-        self.o = o
-        self.c = c
-
-    def __call__(self, store):
-
-        # common path, no inner queries
-        try:
-            if not self.inner:
-                for result in store.triples((self.s, self.p, self.o), self.c):
-                    yield Result(result)
-            else:
-
-                # inner query logic here is definitely _not_ optimized, I
-                # imagine there is all kinds of query optimization and
-                # algebraic reduction that can be applied but that's not
-                # the point, users will have to be aware of the fact that
-                # broad inner queries can significantly impact
-                # performance.
-
-                # first, determine inner subjects
-
-                if self.s is None:
-                    isresult = []
-                    for s in store.uniqueSubjects():
-                        isresult.append(Result((s, None, None)))
-
-                elif type(self.s) is TupleType or IQuery.providedBy(self.s):
-                    if type(self.s) is TupleType:
-                        q = apply(Query, self.s)
-                    else:
-                        q = self.s
-                    isresult = store.query(q)
-                else:
-                    isresult = [Result((self.s, None, None))]
-
-                # determine inner predicates
-
-                if self.p is None:
-                    ipresult = []
-                    for p in store.uniquePredicates():
-                        ipresult.append(Result((None, p, None)))
-
-                elif type(self.p) is TupleType or IQuery.providedBy(self.p):
-                    if type(self.p) is TupleType:
-                        q = apply(Query, self.p)
-                    else:
-                        q = self.p
-                    ipresult = store.query(q)
-
-                else:
-                    ipresult = [Result((None, self.p, None))]
-
-                # determine inner objects
-
-                if self.o is None:
-                    ioresult = []
-                    for o in self.uniqueObjects():
-                        ioresult.append(Result((None, None, o)))
-
-                elif type(self.o) is TupleType or IQuery.providedBy(self.o):
-                    if type(self.o) is TupleType:
-                        q = apply(Query, self.o)
-                    else:
-                        q = self.o
-                    ioresult = store.query(q)
-
-                else:
-                    ioresult = [Result((None, None, self.o))]
-
-                # put it all together
-
-                for sresult in isresult:
-                    for presult in ipresult:
-                        for oresult in ioresult:
-                            yield Result((sresult.subject, presult.predicate, oresult.object))
-        except KeyError:
-            yield None
-
-    def __repr__(self):
-        return "<Query: %s, %s, %s>" % (self.s, self.p, self.o)
-
-class QueryChain(Query):
-    
-    """ Abstract class to combine a "chain" of queries into one result
-    set.  QueryChains are themselves Queries, and can be nested. """
-
-    implements(IQueryChain)
-
-    _queries = None
-
-    def __init__(self, *queries):
-        self._queries = []
-        for x in queries:
-            self.add(x)
-
-    def add(self, query):
-        """ Append a query onto the chain """
-        self._queries.append(query)
-
-    def getQueries(self):
-        """ Return the chain of queries. """
-        return self._queries
-
-    def __call__(self, store):
-        """ Eval a query chain with given args.  Queries throw
-        QueryException to stop chain procesing and declare failure."""
-        
-        raise NotImplementedError
-
-class UnionChain(QueryChain):
-    """
-    Take the union of a chain of queries.
-
-      >>> from triplestore import TripleStore
-      >>> c = TripleStore()
-      >>> u = UnionChain(c, Query())
-      >>> u = UnionChain(c, Query(), Query())      
-
-    """
-
-    def __call__(self, store):
-        results = Set()
-        for query in self._queries:
-            BTrees.OOBTree.union(results, Set(query(store)))
-        for result in results:
-            yield result
-
-class IntersectionChain(QueryChain):
-    """
-    Take the intersection of a chain of queries.
-
-      >>> from triplestore import TripleStore
-      >>> c = TripleStore()
-      >>> i = IntersectionChain(c, Query())
-      >>> i = IntersectionChain(c, Query(), Query())      
-      
-    """
-
-    def __call__(self, store):
-        results = Set()
-        for query in self._queries:
-            results.intersection(query(store))
-        for result in results:
-            yield result
-

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/resources.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/resources.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,46 +0,0 @@
-
-import os, sys
-
-def package_home(gdict):
-    filename = gdict["__file__"]
-    return os.path.dirname(filename)
-
-class Resource(object):
-
-    def __init__(self, filename, _prefix=None):
-        path = self.get_path_from_prefix(_prefix)
-        self.filename = os.path.join(path, filename)
-        if not self.checkResource():
-            raise ValueError("No such resource", self.filename)
-
-    def get_path_from_prefix(self, _prefix):
-        if isinstance(_prefix, str):
-            path = _prefix
-        else:
-            if _prefix is None:
-                _prefix = sys._getframe(2).f_globals
-            path = package_home(_prefix)
-        return path
-
-    def checkResource(self):
-        return True
-
-
-class DirectoryResource(Resource):
-        
-    def checkResource(self):
-        return os.path.isdir(self.filename)
-
-    def list(self):
-        return os.listdir(self.filename)
-
-    def path(self):
-        return self.filename
-
-class FileResource(Resource):
-    
-    def open(self, mode="r"):
-        return open(self.filename, mode)
-
-    def checkResource(self):
-        return os.path.isfile(self.filename)

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/result.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/result.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,77 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-
-__rdf_description__ = '''\
-<rdf:RDF xmlns="http://web.resource.org/cc/"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
-<Work rdf:about="http://zemantic.org/zemantic/result.py"
-  dc:title="zemantic.result"
-  dc:date="2005"
-  dc:description="Result objects.">
-    <dc:creator>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:creator>
-    <dc:rights>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:rights>
-    <license rdf:resource="http://zemantic.org/LICENSE.txt/"/>
-</Work>
-</rdf:RDF>
-'''
-
-
-from interfaces import IResult, IResultSet
-from zope.interface import implements
-from zope.security.proxy import removeSecurityProxy
-
-from BTrees.OOBTree import OOSet
-from rdflib.TripleStore import TripleStore
-from rdflib.backends.InMemoryBackend import InMemoryBackend
-
-class Result(object):
-
-    implements(IResult)
-
-    def __init__(self, (subject, predicate, object)):
-        self.subject = subject
-        self.predicate = predicate
-        self.object = object
-
-    def triple(self):
-        return self.subject, self.predicate, self.object
-
-    def __str__(self):
-        return "<%s, %s, %s>" % (`self.subject`, `self.predicate`, `self.object`)
-
-class ResultSet(object):
-
-    implements(IResultSet)
-
-    def __init__(self, data):
-        self.data = TripleStore(backend=InMemoryBackend())
-        for result in data:
-            if result is not None:
-                s, p, o = result.triple()
-                s = removeSecurityProxy(s)
-                p = removeSecurityProxy(p)
-                o = removeSecurityProxy(o)
-                self.data.add((s, p, o))
-
-    def rdfxml(self):
-        return self.data.serialize()
-
-    def rdfnt(self):
-        return self.data.serialize("nt") 

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/triplestore.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/triplestore.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,204 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-
-__rdf_description__ = '''\
-<rdf:RDF xmlns="http://web.resource.org/cc/"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
-<Work rdf:about="http://zemantic.org/zemantic/zemantic.py"
-  dc:title="zemantic.zemantic"
-  dc:date="2005"
-  dc:description="Triple store catalogs.">
-    <dc:creator>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:creator>
-    <dc:rights>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:rights>
-    <license rdf:resource="http://zemantic.org/LICENSE.txt/"/>
-</Work>
-</rdf:RDF>
-'''
-from persistent import Persistent
-from persistent.dict import PersistentDict
-
-from rdflib.TripleStore import TripleStore as rdflibTripleStore     # not pickleable
-from rdflib.URIRef import URIRef
-from rdflib.BNode import BNode
-from rdflib.Literal import Literal
-from rdflib.Identifier import Identifier
-
-from query import Query
-from lib.ZODBBackend import ZODBBackend
-from lib.IOZODBBackend import IOZODBBackend
-from interfaces import ITripleStore
-from events import afterAdd, beforeRemove
-
-from zope.interface import implements
-from zope.interface.verify import verifyClass
-from zope.app.size.interfaces import ISized
-
-class TripleStore(Persistent):
-    """
-    A semantic zemantic.  A wrapper around a persistent rdflib backend
-    that is used to construct an rdflib triplestore.
-
-      >>> c = TripleStore()
-      >>> ITripleStore.providedBy(c)
-      True
-      >>> verifyClass(ITripleStore, TripleStore)
-      True
-
-    See Zontology class doctests for more tests.
-    
-    """
-
-    implements(ITripleStore)
-
-    _v_store = backend = __parent__ = __name__ = None
-    notify = False
-
-    def __init__(self, backend=None):
-        if backend is None:
-            backend = IOZODBBackend()
-        self.backend = backend
-
-    def clear(self):
-        """
-        Clear zemantic.
-        """
-        for t in self.triples((None, None, None)):
-            self.remove(t)
-
-    def notifyOn(self):
-        """
-        Turn on event notification.
-        """
-        self.notify = True
-
-    def notifyOff(self):
-        self.notify = False
-
-    def getStore(self):
-        """
-        Returns a TripleStore wrapping the semantic storage.
-        """
-        if self._v_store is None:
-            self._v_store = rdflibTripleStore(backend=self.backend)  # not pickleable
-        return self._v_store
-
-    store = property(getStore)
-
-    def parse(self, rdf, format="xml"):
-        """
-        Parse RDF information.  The optional"format" argument can be "xml"
-        (the default) or "nt".  Note, I have not tested nt yet.  Also a
-        bug in rdflib requires you pass a file like object.
-        """
-        self.store.parse(rdf, format=format)
-
-    def add(self, (subject, predicate, object)):
-        """
-        Add a triple to the storage.
-        """
-        t = (subject, predicate, object)
-        self.store.add(t)
-
-        if self.notify:
-            afterAdd(t)
-
-    def remove(self, (subject, predicate, object)):
-        """
-        Add a triple to the storage.
-        """
-        t = (subject, predicate, object)
-        if self.notify:
-            beforeRemove(t)
-
-        self.store.remove(t)
-
-    def triples(self, (subject, predicate, object), *args):
-        """
-        Query the triple storage.  The argument is a triple pattern
-        which can contain a valid value or None to indicate any value
-        is desired.
-        """
-        
-        for triple in  self.store.triples((subject, predicate, object)):
-            yield triple
-
-    def query(self, q):
-        """
-        Query zemantic with a query object.
-        """
-        
-        return q(self)
-
-    # no need to test the rest, they're all based on triples()
-
-    def subjects(self, predicate=None, object=None):
-        return self.store.subjects(predicate, object)
-        
-    def predicates(self, subject=None, object=None):
-        return self.store.predicates(subject, object)
-
-    def objects(self, subject=None, predicate=None):
-        return self.store.objects(subject, predicate)
-
-    def subject_predicates(self, object=None):
-        return self.store.subject_predicates(object)
-            
-    def subject_objects(self, predicate=None):
-        return self.store.subject_objects(predicate)
-        
-    def predicate_objects(self, subject=None):
-        return self.store.predicate_objects(subject)
-
-    def transitive_objects(self, subject, property, remember=None):
-        return self.store.transitive_objects(subject, property, remember)
-
-    def transitive_subjects(self, predicate, object, remember=None):
-        return self.store.transitive_subjects(predicate, object, remember)
-        
-    def uniqueSubjects(self):
-        return self.backend.uniqueSubjects()
-
-    def uniquePredicates(self):
-        return self.backend.uniquePredicates()
-
-    def uniqueObjects(self):
-        return self.backend.uniqueObjects()
-
-    def rdfxml(self):
-        return self.store.serialize()
-
-    def rdfnt(self):
-        return self.store.serialize("nt")
-
-    def __len__(self):
-        return len(self.store)
-
-
-class TripleStoreSized(object):
-    implements(ISized)
-
-    def __init__(self, zemantic):
-        self._zemantic = zemantic
-
-    def sizeForSorting(self):
-        return ('item', len(self._zemantic))
-
-    def sizeForDisplay(self):
-        return str(len(self._zemantic)) + ' triples'

Deleted: /z3/zemantic/branch/tseaver-distutils_reorg/utils.py
==============================================================================
--- /z3/zemantic/branch/tseaver-distutils_reorg/utils.py	Mon Mar 14 18:51:09 2005
+++ (empty file)
@@ -1,94 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004-1005 Michel Pelletier
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-
-
-__rdf_description__ = '''\
-<rdf:RDF xmlns="http://web.resource.org/cc/"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
-<Work rdf:about="http://zemantic.org/zemantic/utils.py"
-  dc:title="zemantic.utils"
-  dc:date="2005"
-  dc:description="Misc stuff.">
-    <dc:creator>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:creator>
-    <dc:rights>
-            <Agent dc:title="Michel Pelletier"/>
-    </dc:rights>
-    <license rdf:resource="http://zemantic.org/LICENSE.txt/"/>
-</Work>
-</rdf:RDF>
-'''
-
-from lib.ZODBBackend import ZODBBackend
-from interfaces import ITripleStore
-from zope.interface import implements
-from urllib import quote, quote_plus
-
-from rdflib.Literal import Literal
-from rdflib.BNode import BNode
-from rdflib.URIRef import URIRef
-
-from triplestore import TripleStore
-from query import Query
-
-class TripleStoreToDotAdapter(object):
-
-    def __init__(self, cat, title=''):
-        """
-        Turn zemantic into a DOT graph
-
-        """
-        self.cat = cat
-        self.title = title
-
-    def toDot(self):
-        out = []
-        bcount = 0
-        lcount = 0
-        out.append('digraph "%s" {' % self.title)
-#        out.append('node [fontname="Courier",fontsize=10,color=Black,fontcolor=Blue];')
-#        out.append('edge [fontname="Courier",fontsize=10,color=Darkgreen,fontcolor=Red];')
-        out.append('rankdir=LR;')
-        cat = self.cat
-        for r in cat.query(Query()):
-
-            sname = oname = None
-            if r.subject.startswith('_'):
-                bcount += 1
-                sname = 'Blank_' + str(bcount)
-            else:
-                sname = r.subject.n3()
-
-            if r.object.startswith('"'):
-                lcount += 1
-                oname = 'Literal_' + str(lcount)
-            else:
-                oname = r.object.n3()
-
-            out.append('%s [label="%s"];' % (sname.replace('"', ''), r.subject.n3().replace('"', '\"')))
-            out.append('%s -> %s [label="%s"];' % (sname.replace('"', ''), oname.replace('"', ''), r.predicate.n3().replace('"', '\"')))
-            out.append('%s [shape="box", label="%s"];' % (oname.replace('"', ''), r.object.n3().replace('"', '\"')))
-
-        out.append('}')
-        return '\n'.join(out)
-
-
-def shorten(s):
-    if s > 30:
-        return s[:13]+'...'+s[-13:]
-    return s
-
-


More information about the z3-checkins mailing list