From 3451af94fb05cd7d545718c84afcb4fe081a8f85 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 24 Mar 2019 21:22:36 +0100 Subject: Use lighter and more consistent documentation style --- lv2specgen/lv2specgen.py | 106 +++++++++++++++++++------------------- lv2specgen/template.html | 130 ++++++++++++++++++++++++----------------------- 2 files changed, 119 insertions(+), 117 deletions(-) (limited to 'lv2specgen') diff --git a/lv2specgen/lv2specgen.py b/lv2specgen/lv2specgen.py index c8612e1..dd77b9c 100755 --- a/lv2specgen/lv2specgen.py +++ b/lv2specgen/lv2specgen.py @@ -466,30 +466,14 @@ def getTermLink(uri, subject=None, predicate=None): return '%s' % (uri, extra, niceName(uri)) -def rdfsClassInfo(term, m): - """Generate rdfs-type information for Classes: ranges, and domains.""" - global classranges - global classdomains +def owlRestrictionInfo(term, m): + """Generate OWL restriction information for Classes""" doc = "" - # Find subClassOf information restrictions = [] - superclasses = [] - for st in findStatements(m, term, rdfs.subClassOf, None): - if not isBlank(getObject(st)): - uri = getObject(st) - if not uri in superclasses: - superclasses.append(uri) - else: - meta_type = findOne(m, getObject(st), rdf.type, None) - restrictions.append(getSubject(meta_type)) - - if len(superclasses) > 0: - doc += "\nSubclass of" - first = True - for superclass in sorted(superclasses): - doc += getProperty(getTermLink(superclass), first) - first = False + for s in findStatements(m, term, rdfs.subClassOf, None): + if findOne(m, getObject(s), rdf.type, owl.Restriction): + restrictions.append(getObject(s)) for r in sorted(restrictions): props = findStatements(m, r, None, None) @@ -501,38 +485,49 @@ def rdfsClassInfo(term, m): elif getPredicate(p) == rdfs.comment: comment = getObject(p) if onProp is not None: - doc += 'Restriction on %s' % getTermLink(onProp) + doc += '
Restriction on %s
\n' % getTermLink(onProp) prop_str = '' - last_pred = None - first = True for p in findStatements(m, r, None, None): if (getPredicate(p) == owl.onProperty or getPredicate(p) == rdfs.comment or (getPredicate(p) == rdf.type and getObject(p) == owl.Restriction) or getPredicate(p) == lv2.documentation): - last_pred = None continue - if getPredicate(p) != last_pred: - prop_str += '%s\n' % getTermLink(getPredicate(p)) - first = True + prop_str += getTermLink(getPredicate(p)) + if isResource(getObject(p)): - prop_str += getProperty(getTermLink(getObject(p)), first) - first = False + prop_str += ' ' + getTermLink(getObject(p)) elif isLiteral(getObject(p)): - prop_str += getProperty(getLiteralString(getObject(p)), first) - first = False + prop_str += ' ' + getLiteralString(getObject(p)) - last_pred = getPredicate(p) + if comment is not None: + prop_str += '\n
%s
\n' % getLiteralString(comment) - prop_str += endProperties(first) + doc += '
%s
' % prop_str if prop_str else ''; - if prop_str != '': - doc += '%s
\n' % prop_str - if comment is not None: - doc += "%s\n" % getLiteralString(comment) - doc += '' + return doc + +def rdfsClassInfo(term, m): + """Generate rdfs-type information for Classes: ranges, and domains.""" + global classranges + global classdomains + doc = "" + + # Find subClassOf information + superclasses = set() + for st in findStatements(m, term, rdfs.subClassOf, None): + if not isBlank(getObject(st)): + uri = getObject(st) + superclasses |= set([uri]) + + if len(superclasses) > 0: + doc += "\nSubclass of" + first = True + for superclass in sorted(superclasses): + doc += getProperty(getTermLink(superclass), first) + first = False # Find out about properties which have rdfs:domain of t d = classdomains.get(str(term), "") @@ -683,27 +678,15 @@ def docTerms(category, list, m, classlist, proplist, instalist): is_deprecated = isDeprecated(m, term) doc += '
' - if label != '' or comment != '' or is_deprecated: - doc += '
' - - if label != '': - doc += "
%s
" % label - - if is_deprecated: - doc += '
DEPRECATED
' - - if comment != '': - doc += "
%s
" % comment - - if label != '' or comment != '' or is_deprecated: - doc += "
" terminfo = "" + extrainfo = "" if category == 'Property': terminfo += owlInfo(term, m) terminfo += rdfsPropertyInfo(term, m) if category == 'Class': terminfo += rdfsClassInfo(term, m) + extrainfo += owlRestrictionInfo(term, m) if category == 'Instance': terminfo += rdfsInstanceInfo(term, m) @@ -712,6 +695,23 @@ def docTerms(category, list, m, classlist, proplist, instalist): if (len(terminfo) > 0): # to prevent empty list (bug #882) doc += '\n%s
\n' % terminfo + if label != '' or comment != '' or is_deprecated: + doc += '
' + + if label != '': + doc += "
%s
" % label + + if is_deprecated: + doc += '
Deprecated
' + + if comment != '': + doc += "
%s
" % comment + + doc += extrainfo + + if label != '' or comment != '' or is_deprecated: + doc += "
" + doc += '
' doc += "\n\n\n" diff --git a/lv2specgen/template.html b/lv2specgen/template.html index 5056aef..9d25d80 100644 --- a/lv2specgen/template.html +++ b/lv2specgen/template.html @@ -17,77 +17,79 @@ - -
-