From 753a7b7b75c6e69e0d6c659c8772381b31e17ee4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 17 Mar 2011 04:42:44 +0000 Subject: List properties in a (more compact than
). --- lv2specgen/lv2specgen.py | 141 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 97 insertions(+), 44 deletions(-) (limited to 'lv2specgen') diff --git a/lv2specgen/lv2specgen.py b/lv2specgen/lv2specgen.py index 1b210ce..c9b4640 100755 --- a/lv2specgen/lv2specgen.py +++ b/lv2specgen/lv2specgen.py @@ -144,6 +144,19 @@ def getComment(m, urinode): return '' +def getProperty(val, first=True): + "Return a string representing a property value in a property table" + doc = '' + if not first: + doc += '
' # Empty cell in header column + doc += '\n' % val + return doc + +def endProperties(first): + if first: + return '' + else: + return '' def owlVersionInfo(m): v = m.find_statements(RDF.Statement(None, owl.versionInfo, None)) @@ -152,7 +165,6 @@ def owlVersionInfo(m): else: return "" - def rdfsPropertyInfo(term,m): """Generate HTML for properties: Domain, range""" global classranges @@ -165,10 +177,12 @@ def rdfsPropertyInfo(term,m): o = m.find_statements( RDF.Statement(term, rdfs.subPropertyOf, None) ) if o.current(): rlist = '' + first = True for st in o: k = getTermLink(str(st.object.uri), term, rdfs.subPropertyOf) - rlist += "
%s
" % k - doc += "
Sub-property of
%s" % rlist + rlist += getProperty(k, first) + first = False + doc += "%s" % rlist # Domain stuff domains = m.find_statements(RDF.Statement(term, rdfs.domain, None)) @@ -177,14 +191,16 @@ def rdfsPropertyInfo(term,m): collection = m.find_statements(RDF.Statement(d.object, owl.unionOf, None)) if collection.current(): uris = parseCollection(m, collection) + first = True for uri in uris: - domainsdoc += "
%s
" % getTermLink(uri, term, rdfs.domain) + domainsdoc += getProperty(getTermLink(uri, term, rdfs.domain), first) add(classdomains, uri, term.uri) + first = False else: if not d.object.is_blank(): - domainsdoc += "
%s
" % getTermLink(str(d.object.uri), term, rdfs.domain) + domainsdoc += getProperty(getTermLink(str(d.object.uri), term, rdfs.domain)) if (len(domainsdoc)>0): - doc += "
Domain
%s" % domainsdoc + doc += "%s" % domainsdoc # Range stuff ranges = m.find_statements(RDF.Statement(term, rdfs.range, None)) @@ -193,14 +209,16 @@ def rdfsPropertyInfo(term,m): collection = m.find_statements(RDF.Statement(r.object, owl.unionOf, None)) if collection.current(): uris = parseCollection(m, collection) + first = True for uri in uris: - rangesdoc += "
%s
" % getTermLink(uri, term, rdfs.range) + rangesdoc += getProperty(getTermLink(uri, term, rdfs.range), first) add(classranges, uri, term.uri) + first = False else: if not r.object.is_blank(): - rangesdoc += "
%s
" % getTermLink(str(r.object.uri), term, rdfs.range) + rangesdoc += getProperty(getTermLink(str(r.object.uri), term, rdfs.range)) if (len(rangesdoc)>0): - doc += "
Range
%s" % rangesdoc + doc += "%s" % rangesdoc return doc @@ -229,8 +247,7 @@ def getTermLink(uri, subject=None, predicate=None): return '%s' % (uri.replace(spec_ns_str, ""), extra, niceName(uri)) else: return '%s' % (uri, extra, niceName(uri)) - - + def rdfsClassInfo(term,m): """Generate rdfs-type information for Classes: ranges, and domains.""" global classranges @@ -252,9 +269,11 @@ def rdfsClassInfo(term,m): restrictions.append(meta_types.current().subject) if len(superclasses) > 0: - doc += "\n
Sub-class of
" + doc += "\n" + first = True for superclass in superclasses: - doc += "
%s
" % getTermLink(superclass) + doc += getProperty(getTermLink(superclass), first) + first = False for r in restrictions: props = m.find_statements(RDF.Statement(r, None, None)) @@ -266,47 +285,65 @@ def rdfsClassInfo(term,m): elif p.predicate == rdfs.comment: comment = p.object if onProp != None: - doc += '
Restriction on property %s
\n' % getTermLink(onProp.uri) - doc += '
\n' - if comment != None: - doc += "%s\n" % comment.literal_value['string'] + doc += '
\n' % getTermLink(str(p.predicate.uri)) + first = True + if p.object.is_resource(): + prop_str += getProperty(getTermLink(p.object.uri), first) + first = False + elif p.object.is_literal(): + prop_str += getProperty(p.object.literal_value['string'], first) + first = False + + last_pred = p.predicate + + prop_str += endProperties(first) + if prop_str != '': - doc += '
%s
\n' % prop_str - doc += '' + doc += '
%s
Sub-property of
Domain
Range
Sub-class of
Restriction on %s' % getTermLink(onProp.uri) prop_str = '' + last_pred = None + first = True for p in m.find_statements(RDF.Statement(r, None, None)): - if p.predicate != owl.onProperty and p.predicate != rdfs.comment and not( - p.predicate == rdf.type and p.object == owl.Restriction) and p.predicate != lv2.documentation: - if p.object.is_resource(): - prop_str += '\n
%s
%s
\n' % ( - getTermLink(p.predicate.uri), getTermLink(p.object.uri)) - elif p.object.is_literal(): - prop_str += '\n
%s
%s
\n' % ( - getTermLink(p.predicate.uri), p.object.literal_value['string']) + if (p.predicate == owl.onProperty + or p.predicate == rdfs.comment + or (p.predicate == rdf.type and p.object == owl.Restriction) + or p.predicate == lv2.documentation): + last_pred = None + continue + + if p.predicate != last_pred: + prop_str += '
%s
%s
\n' % prop_str + if comment != None: + doc += "%s\n" % comment.literal_value['string'] + doc += '' # Find out about properties which have rdfs:domain of t d = classdomains.get(str(term.uri), "") if d: dlist = '' + first = True for k in d: - dlist += "
%s
" % getTermLink(k) - doc += "
In domain of
" + dlist + dlist += getProperty(getTermLink(k), first) + first = False + doc += "In domain of%s" % dlist # Find out about properties which have rdfs:range of t r = classranges.get(str(term.uri), "") if r: rlist = '' + first = True for k in r: - rlist += "
%s
" % getTermLink(k) - doc += "
In range of
" + rlist + rlist += getProperty(getTermLink(k), first) + first = False + doc += "In range of%s" % rlist return doc def isSpecial(pred): """Return True if the predicate is "special" and shouldn't be emitted generically""" - return pred in [rdf.type, rdfs.range, rdfs.domain, rdfs.label, rdfs.comment, rdfs.subClassOf, lv2.documentation] + return pred in [rdf.type, rdfs.range, rdfs.domain, rdfs.label, rdfs.comment, rdfs.subClassOf, rdfs.subPropertyOf, lv2.documentation] def blankNodeDesc(node,m): @@ -336,21 +373,28 @@ def extraInfo(term,m): """Generate information about misc. properties of a term""" doc = "" properties = m.find_statements(RDF.Statement(term, None, None)) - last_pred = '' + last_pred = None + first = True for p in properties: if isSpecial(p.predicate): + last_pred = None continue if p.predicate != last_pred: - doc += '
%s
\n' % getTermLink(str(p.predicate.uri)) + doc += '%s\n' % getTermLink(str(p.predicate.uri)) + first = True if p.object.is_resource(): - doc += '
%s
\n' % getTermLink(str(p.object.uri), term, p.predicate) + doc += getProperty(getTermLink(str(p.object.uri), term, p.predicate), first) elif p.object.is_literal(): - doc += '
%s
\n' % str(p.object) + doc += getProperty(str(p.object), first) elif p.object.is_blank(): - doc += '
' + blankNodeDesc(p.object,m) + '
\n' + doc += getProperty(str(blankNodeDesc(p.object, m)), first) else: - doc += '
?
\n' + doc += getProperty('?', first) + first = False last_pred = p.predicate + + #doc += endProperties(first) + return doc @@ -361,11 +405,17 @@ def rdfsInstanceInfo(term,m): term = RDF.Uri(term) t = m.find_statements(RDF.Statement(term, rdf.type, None)) if t.current(): - doc += "
Type
" + doc += "Type" + first = True while t.current(): - doc += "
%s
" % getTermLink(RDF.Node(t.current().object), RDF.Node(term), rdf.type) + doc += getProperty(getTermLink(RDF.Node(t.current().object), + RDF.Node(term), + rdf.type), + first) + first = False t.next() + doc += endProperties(first) doc += extraInfo(RDF.Node(term), m) return doc @@ -378,14 +428,17 @@ def owlInfo(term,m): # Inverse properties ( owl:inverseOf ) o = m.find_statements(RDF.Statement(term, owl.inverseOf, None)) if o.current(): - res += "
Inverse:
" + res += "Inverse:\n" + first = True for st in o: - res += "
%s
" % getTermLink(str(st.object.uri)) + res += getProperty(getTermLink(str(st.object.uri)), first) + first = False + res += endProperties(first) def owlTypeInfo(term, propertyType, name): o = m.find_statements(RDF.Statement(term, rdf.type, propertyType)) if o.current(): - return "
OWL Type
%s
\n" % name + return "OWL Type%s\n" % name else: return "" @@ -455,7 +508,7 @@ def docTerms(category, list, m): terminfo += extraInfo(term,m) if (len(terminfo)>0): #to prevent empty list (bug #882) - doc += '\n
%s
\n' % terminfo + doc += '\n%s
\n' % terminfo doc += '' doc += "\n\n\n" -- cgit v1.2.1