示例#1
0
class LiteralStatement(models.Model):
    """
    Statement where the object is a literal.
    """

    id = UUIDField("ID", primary_key=True)
    subject = fields.URIField(verbose_name=_("Subject"), db_index=True)
    predicate = fields.URIField(_("Predicate"), db_index=True)
    object = fields.LiteralField(_("Object"), db_index=True)
    context = models.ForeignKey(NamedGraph, verbose_name=_("Context"))

    class Meta:  # pylint: disable=C1001
        unique_together = ('subject', 'predicate', 'object', 'context')

    def __unicode__(self):
        return u"{0}, {1}".format(self.as_triple(), self.context.identifier)    # pylint: disable=E1101

    def as_triple(self):
        """
        Converts this predicate to a triple.
        """
        return self.subject, self.predicate, self.object
示例#2
0
class NamedGraph(models.Model):
    """
    Models a context which represents a named graph.
    """

    identifier = fields.URIField(verbose_name=_("Identifier"), unique=True)

    class Meta:  # pylint: disable=C1001
        verbose_name = _("named graph")
        verbose_name_plural = _("named graphs")

    def __unicode__(self):
        return u"{0}".format(self.identifier)
class URIStatement(models.Model):
    """
    Statement where the object is a URI.
    """

    id = models.UUIDField("ID", default=uuid.uuid4, primary_key=True)
    subject = fields.URIField(verbose_name=_("Subject"), db_index=True)
    predicate = fields.URIField(_("Predicate"), db_index=True)
    object = fields.URIField(_("Object"), db_index=True)
    context = models.ForeignKey(NamedGraph,
                                verbose_name=_("Context"),
                                on_delete=models.CASCADE)

    class Meta:
        unique_together = ('subject', 'predicate', 'object', 'context')

    def __str__(self):
        return "{}, {}".format(self.as_triple(), self.context.identifier)

    def as_triple(self):
        """
        Converts this predicate to a triple.
        """
        return self.subject, self.predicate, self.object
class NamedGraph(models.Model):
    """
    Models a context which represents a named graph.
    """

    identifier = fields.URIField(verbose_name=_("Identifier"), db_index=True)

    store = models.ForeignKey(Store,
                              verbose_name=_("Store"),
                              on_delete=models.CASCADE,
                              db_index=True)

    class Meta:
        verbose_name = _("named graph")
        verbose_name_plural = _("named graphs")
        unique_together = [
            ("identifier", "store"),
        ]

    def __str__(self):
        return "{}-{}".format(self.identifier, "identifier")