コード例 #1
0
ファイル: constructs.py プロジェクト: kbarber/owlsugar
 def __init__(self, *oargs, **nargs):
     """Initialise an OWL function.
     
         args: an argument list for auto-populating associations upon creation
             of an object.
     
     """
     # Some helper variables to make typing easier
     self._universe = OwlUniverse.get_universe()
     
     # If we are an abstract - then throw an exception
     if self.is_abstract() is True:
         raise Exception("Cannot instantiate an abstract class")
     
     # Prepare data stores
     self._references = dict()
     self._data = dict()
     for attr in self.associations():
         self._data[attr.id()] = None
         setattr(self, attr.id(), attr(self))
     
     # For each named argument, run its method
     for k,v in nargs.iteritems():
         self.association(k, v)
 
     # TODO: We should be mandating that objects are instantiated with
     #    mandatory associations provided as arguments at creation time.
     #    This involves some sort of positive validation I suppose.
 
     # And register the instance in the universe
     self._universe.add_object(self)
コード例 #2
0
    def __init__(self, *oargs, **nargs):
        """Initialise an OWL function.
        
            args: an argument list for auto-populating associations upon creation
                of an object.
        
        """
        # Some helper variables to make typing easier
        self._universe = OwlUniverse.get_universe()

        # If we are an abstract - then throw an exception
        if self.is_abstract() is True:
            raise Exception("Cannot instantiate an abstract class")

        # Prepare data stores
        self._references = dict()
        self._data = dict()
        for attr in self.associations():
            self._data[attr.id()] = None
            setattr(self, attr.id(), attr(self))

        # For each named argument, run its method
        for k, v in nargs.iteritems():
            self.association(k, v)

        # TODO: We should be mandating that objects are instantiated with
        #    mandatory associations provided as arguments at creation time.
        #    This involves some sort of positive validation I suppose.

        # And register the instance in the universe
        self._universe.add_object(self)
コード例 #3
0
ファイル: constructs.py プロジェクト: kbarber/owlsugar
 def class_type(cls):
     """Return the class that this association pertains to.
     
     """
     universe = OwlUniverse.get_universe()
     return universe.get_class(_model.association_attr(cls.classid(), 
         cls.id())['type'])
コード例 #4
0
 def class_type(cls):
     """Return the class that this association pertains to.
     
     """
     universe = OwlUniverse.get_universe()
     return universe.get_class(
         _model.association_attr(cls.classid(), cls.id())['type'])
コード例 #5
0
ファイル: constructs.py プロジェクト: kbarber/owlsugar
 def child_classes(cls):
     """Return a list of child classes.
     
     """
     universe = OwlUniverse.get_universe()
     children = list()
     for i in _model.class_children(cls.id()):
         children.append(universe.get_class(i))
         
     return children
コード例 #6
0
ファイル: constructs.py プロジェクト: kbarber/owlsugar
 def ref_classes(cls):
     """Return a list of classes that may reference this class.
     
     """
     universe = OwlUniverse.get_universe()
     refs = list()
     for i in _model.references(cls.id()):
         refs.append(universe.get_class(i))
         
     return refs
コード例 #7
0
    def child_classes(cls):
        """Return a list of child classes.
        
        """
        universe = OwlUniverse.get_universe()
        children = list()
        for i in _model.class_children(cls.id()):
            children.append(universe.get_class(i))

        return children
コード例 #8
0
    def ref_classes(cls):
        """Return a list of classes that may reference this class.
        
        """
        universe = OwlUniverse.get_universe()
        refs = list()
        for i in _model.references(cls.id()):
            refs.append(universe.get_class(i))

        return refs
コード例 #9
0
ファイル: functional.py プロジェクト: kbarber/owlsugar
from owlsugar.universe import OwlUniverse
from owlsugar.constructs import *

# First initialise the universe
universe = OwlUniverse() 

a = Namespace()
a.newinit("foo", "<http://bob.sh/#>")

# Test Structure
ont = Ontology(
    ontologyURI=URI(uri="<http://bob.sh/>"), 
    annotations=[
        AnnotationByConstant(
            annotationURI=URI(uri="fooannotation"),
            annotationValue=Constant(value="foo", 
            datatypeURI=URI(uri="<http://foo.com/#fooType>"))),
        Label("Testing a label")
        ],
        
    axioms=[
        Declaration(entity=Individual(entityURI=URI(uri="#foot"))), 
        Declaration(entity=Individual(entityURI=URI(uri="#shin"))),
        ])

# Extract information from elements defined above
print "Axiom:", ont.axioms()
print "Annotations:", ont.annotations()
print "All classes:", universe.get_classes()
print "Ontology class:", universe.get_class("Ontology")
print "Ontology objects:", universe.get_objects("Ontology")
コード例 #10
0
ファイル: functional.py プロジェクト: UrkoM/owlsugar
from owlsugar.universe import OwlUniverse
from owlsugar.constructs import *

# First initialise the universe
universe = OwlUniverse()

a = Namespace()
a.newinit("foo", "<http://bob.sh/#>")

# Test Structure
ont = Ontology(ontologyURI=URI(uri="<http://bob.sh/>"),
               annotations=[
                   AnnotationByConstant(
                       annotationURI=URI(uri="fooannotation"),
                       annotationValue=Constant(
                           value="foo",
                           datatypeURI=URI(uri="<http://foo.com/#fooType>"))),
                   Label("Testing a label")
               ],
               axioms=[
                   Declaration(entity=Individual(entityURI=URI(uri="#foot"))),
                   Declaration(entity=Individual(entityURI=URI(uri="#shin"))),
               ])

# Extract information from elements defined above
print "Axiom:", ont.axioms()
print "Annotations:", ont.annotations()
print "All classes:", universe.get_classes()
print "Ontology class:", universe.get_class("Ontology")
print "Ontology objects:", universe.get_objects("Ontology")
print "Declaration objects:", universe.get_objects("Declaration")