Beispiel #1
0
    def loadComment(self):
        comments = self.getComments()
        wpre = None
        name = self.termdesc.id
        if name.startswith(
                "http:"
        ):  #Wikilinks in markdown default to current site - extermals need overriding
            val = os.path.basename(name)
            wpre = name[:len(name) - len(val)]

        first = True
        buf = []
        for com in comments:
            if not first:
                buf.append(" ")
            else:
                first = False
            if SdoTermSource.MARKDOWNPROCESS:
                buf.append(Markdown.parse(com, wpre=wpre))
            else:
                buf.append(com)
        ret = ''.join(buf)
        if not len(ret):
            ret = ""
        self.comment = ret
Beispiel #2
0
    def outputType(self, uri, graph):
        self.typesCount += 1

        typ = SubElement(self.dom, "owl:Class")
        typ.set("rdf:about", uri)
        ext = None
        for (p, o) in graph.predicate_objects(uri):
            if p == RDFS.label:
                l = SubElement(typ, "rdfs:label")
                l.set("xml:lang", "en")
                l.text = o
            elif p == RDFS.comment:
                c = SubElement(typ, "rdfs:comment")
                c.set("xml:lang", "en")
                c.text = Markdown.parse(o)
            elif p == RDFS.subClassOf:
                s = SubElement(typ, "rdfs:subClassOf")
                s.set("rdf:resource", o)
            elif p == URIRef(VOCABURI + "isPartOf"):  #Defined in an extension
                ext = str(o)
            elif p == RDF.type and o == URIRef(VOCABURI +
                                               "DataType"):  #A datatype
                s = SubElement(typ, "rdfs:subClassOf")
                s.set("rdf:resource", VOCABURI + "DataType")

        typ.append(self.addDefined(uri, ext))
Beispiel #3
0
 def test_emph(self):
     from localmarkdown import Markdown
     markstring = "This is _em_, __strong__, ___strong em___"
     html = Markdown.parse(markstring, True)
     self.assertFalse(
         html !=
         "<p>This is <em>em</em>, <strong>strong</strong>, <strong><em>strong em</em></strong></p>\n",
         "Markdown string not formatted correctly")
Beispiel #4
0
    def outputNamedIndividuals(self, idividual, graph, parent=None):
        self.namedCount += 1

        typ = SubElement(self.dom, "owl:NamedIndividual")
        typ.set("rdf:about", idividual)
        ext = None
        for (p, o) in graph.predicate_objects(URIRef(idividual)):
            if p == RDFS.label:
                l = SubElement(typ, "rdfs:label")
                l.set("xml:lang", "en")
                l.text = o
            elif p == RDFS.comment:
                c = SubElement(typ, "rdfs:comment")
                c.set("xml:lang", "en")
                c.text = Markdown.parse(o)
            elif p == URIRef(VOCABURI + "isPartOf"):
                ext = str(o)

        typ.append(self.addDefined(idividual, ext))

        if parent:
            s = SubElement(typ, "rdfs:subClassOf")
            s.set("rdf:resource", parent)
Beispiel #5
0
    def outputProp(self, uri, graph):
        self.propsCount += 1
        children = []
        domains = {}
        ranges = []
        datatypeonly = True
        ext = None
        for (p, o) in graph.predicate_objects(uri):
            if p == RDFS.label:
                l = Element("rdfs:label")
                l.set("xml:lang", "en")
                l.text = o
                children.append(l)
            elif p == RDFS.comment:
                c = Element("rdfs:comment")
                c.set("xml:lang", "en")
                c.text = Markdown.parse(o)
                children.append(c)
            elif p == RDFS.subPropertyOf:
                sub = Element("rdfs:subPropertyOf")
                subval = str(o)
                if subval == "rdf:type":  #Fixes a special case with schema:additionalType
                    subval = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"

                sub.set("rdf:resource", subval)
                children.append(sub)
            elif p == INVERSEOF:
                sub = Element("owl:inverseOf")
                sub.set("rdf:resource", o)
                children.append(sub)
            elif p == SUPERSEDEDBY:
                sub = Element("schema:supersededBy")
                sub.set("rdf:resource", o)
                children.append(sub)
            elif p == DOMAININC:
                domains[o] = True
            elif p == RANGEINC:
                ranges.append(str(o))
                if str(o) not in DATATYPES:
                    datatypeonly = False
            elif p == URIRef(VOCABURI + "isPartOf"):
                ext = str(o)

        children.append(self.addDefined(uri, ext))

        if not datatypeonly:
            for r in DEFAULTRANGES:
                if r not in ranges:
                    ranges.append(r)

        if len(domains):
            d = Element("rdfs:domain")
            children.append(d)
            cl = SubElement(d, "owl:Class")
            u = SubElement(cl, "owl:unionOf")
            u.set("rdf:parseType", "Collection")
            for target in domains.keys():
                targ = SubElement(u, "owl:Class")
                targ.set("rdf:about", target)

        if len(ranges):
            r = Element("rdfs:range")
            children.append(r)
            cl = SubElement(r, "owl:Class")
            u = SubElement(cl, "owl:unionOf")
            u.set("rdf:parseType", "Collection")
            for target in ranges:
                targ = SubElement(u, "owl:Class")
                targ.set("rdf:about", target)

        if datatypeonly:
            prop = SubElement(self.dom, "owl:DatatypeProperty")
        else:
            prop = SubElement(self.dom, "owl:ObjectProperty")
        prop.set("rdf:about", uri)
        for sub in children:
            prop.append(sub)