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
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))
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")
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)
import sys if not (sys.version_info.major == 3 and sys.version_info.minor > 5): print("Python version %s.%s not supported version 3.6 or above required - exiting" % (sys.version_info.major,sys.version_info.minor)) sys.exit(1) # To be executed in the SchemaTerms/example-code/{example} directory import os for path in [os.getcwd(),"..","../..","../../.."]: #Adds in current, example-code, and SchemaTerms directory into path sys.path.insert( 1, path ) #Pickup libs from local directories from sdotermsource import * from sdoterm import * from localmarkdown import Markdown Markdown.setWikilinkCssClass("localLink") Markdown.setWikilinkPrePath("/") triplesfile = "../data/schemaorg-all-http.nt" SdoTermSource.VOCABURI = "https://schema.org/" #Force to https as loaded https file SdoTermSource.loadSourceGraph(triplesfile) print ("loaded %s triples" % len(SdoTermSource.sourceGraph())) terms = SdoTermSource.getAllTerms() print ("Terms Count: %s" % len(terms)) from schematermsprotobuf import sdotermToProtobuf, sdotermToProtobufMsg, sdotermToProtobufText, protobufToMsg, protobufToText import time,datetime
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)
import io for path in [ os.getcwd(), "software/Util", "software/SchemaTerms", "software/SchemaExamples", "software/scripts" ]: sys.path.insert(1, path) #Pickup libs from local directories from buildsite import * from sdotermsource import SdoTermSource, VOCABURI from sdoterm import * from localmarkdown import Markdown VOCABURI = SdoTermSource.vocabUri() ################################################### #MARKDOWN INITIALISE ################################################### Markdown.setWikilinkCssClass("localLink") Markdown.setWikilinkPrePath("https://schema.org/") #Production site uses no suffix in link - mapping to file done in server config Markdown.setWikilinkPostPath("") def fileName(fn): ret = OUTPUTDIR + '/' + fn checkFilePath(os.path.dirname(ret)) return ret CACHECONTEXT = None def jsonldcontext(page):