How to use the ontospy.core.entities.RDF_Entity function in ontospy

To help you get started, we’ve selected a few ontospy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lambdamusic / Ontospy / ontospy / core / entities.py View on Github external
def instances(self):  # = all instances
        if self._instances == False:
            # calculate and set
            self._instances = []
            if self.sparqlHelper:
                qres = self.sparqlHelper.getClassInstances(self.uri)
                for uri in [x[0] for x in qres]:
                    instance = RDF_Entity(uri, self.uri, self.namespaces)
                    instance.triples = self.sparqlHelper.entityTriples(
                        instance.uri)
                    instance._buildGraph()  # force construction of mini graph
                    self._instances += [instance]

            return self._instances
        else:
            # it's been calc already, hence return
            return self._instances
github lambdamusic / Ontospy / ontospy / core / entities.py View on Github external
printDebug("Ancestors....: %d" % len(self.ancestors()))
        printDebug("Descendants..: %d" % len(self.descendants()))
        printDebug("----------------")

    def printGenericTree(self):
        printGenericTree(self)

    def describe(self):
        """ shotcut to pull out useful info for interactive use """
        # self.printTriples()
        printDebug(self.uri, "green")
        self.printStats()
        self.printGenericTree()


class OntoShape(RDF_Entity):
    """
    Python representation of a SHACL shape.

    """

    def __init__(self, uri, rdftype=None, namespaces=None, ext_model=False):
        """
        ...
        """
        super(OntoShape, self).__init__(uri, rdftype, namespaces, ext_model)
        self.slug = "shape-" + slugify(self.qname)
        self.ontology = None
        self.targetClasses = []
        self.sparqlHelper = None  # the original graph the class derives from

    def __repr__(self):
github lambdamusic / Ontospy / ontospy / core / entities.py View on Github external
return sorted(self.triples)

    def describe(self):
        """ shotcut to pull out useful info for interactive use """
        # self.printGenericTree()
        # self.printTriples()
        printDebug(self.uri, "green")
        self.stats()

    def stats(self):
        """ shotcut to pull out useful info for interactive use """
        printDebug("Classes.....: %d" % len(self.all_classes))
        printDebug("Properties..: %d" % len(self.all_properties))


class OntoClass(RDF_Entity):
    """
    Python representation of a generic class within an ontology.
    Includes methods for representing and querying RDFS/OWL classes


    domain_of_inferred: a list of dict
            [{:
            [,,
                etc....]},
        {:
            [, etc...]},
            ]
    """

    def __init__(self, uri, rdftype=None, namespaces=None, ext_model=False):
        """
github lambdamusic / Ontospy / ontospy / core / entities.py View on Github external
printDebug("Children.....: %d" % len(self.children()))
        printDebug("Ancestors....: %d" % len(self.ancestors()))
        printDebug("Descendants..: %d" % len(self.descendants()))
        printDebug("Has Domain...: %d" % len(self.domains))
        printDebug("Has Range....: %d" % len(self.ranges))
        printDebug("----------------")

    def describe(self):
        """ shotcut to pull out useful info for interactive use """
        # self.printTriples()
        printDebug(self.uri, "green")
        self.printStats()
        # self.printGenericTree()


class OntoSKOSConcept(RDF_Entity):
    """
    Python representation of a generic SKOS concept within an ontology.
    @todo: complete methods..

    """

    def __init__(self, uri, rdftype=None, namespaces=None, ext_model=False):
        """
        ...
        """
        super(OntoSKOSConcept, self).__init__(uri, rdftype, namespaces,
                                              ext_model)
        self.slug = "concept-" + slugify(self.qname)
        self.instance_of = []
        self.ontology = None
        self.sparqlHelper = None  # the original graph the class derives from
github lambdamusic / Ontospy / ontospy / core / entities.py View on Github external
printDebug("Range of.....: %d" % len(self.range_of))
        printDebug("Instances....: %d" % self.count())
        printDebug("----------------")

    def printGenericTree(self):
        printGenericTree(self)

    def describe(self):
        """ shotcut to pull out useful info for interactive use """
        # self.printTriples()
        printDebug(self.uri, "green")
        self.printStats()
        # self.printGenericTree()


class OntoProperty(RDF_Entity):
    """
    Python representation of a generic RDF/OWL property.

    rdftype is one of:
    rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#ObjectProperty')
    rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#DatatypeProperty')
    rdflib.term.URIRef(u'http://www.w3.org/2002/07/owl#AnnotationProperty')
    rdflib.term.URIRef(u'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property')

    """

    def __init__(self, uri, rdftype=None, namespaces=None, ext_model=False):
        """
        ...
        """
        super(OntoProperty, self).__init__(uri, rdftype, namespaces, ext_model)
github lambdamusic / Ontospy / ontospy / core / entities.py View on Github external
rdflib.RDFS.comment, rdflib.namespace.DCTERMS.description,
            rdflib.namespace.DC.description, rdflib.namespace.SKOS.definition
        ]

        for pred in test_preds:
            test = self.getValuesForProperty(pred)
            # printDebug(str(test), "red")
            if test:
                if quotes:
                    return addQuotes(joinStringsInList(test, prefLanguage))
                else:
                    return joinStringsInList(test, prefLanguage)
        return ""


class Ontology(RDF_Entity):
    """
    Pythonic representation of an OWL ontology
    """

    def __repr__(self):
        return "" % (self.uri)

    def __init__(self,
                 uri,
                 rdftype=None,
                 namespaces=None,
                 prefPrefix="",
                 ext_model=False):
        """
        Init ontology object. Load the graph in memory, then setup all necessary attributes.
        """