Changeset 2125

Show
Ignore:
Timestamp:
06/16/09 21:30:37 (15 months ago)
Author:
drobilla
Message:

Emit property restriction documentation.

Location:
trunk/lv2specgen
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lv2specgen/lv2specgen.py

    r2120 r2125  
    106106 
    107107 
    108 def termlink(string): 
    109     """FOAF specific: function which replaces <code>foaf:*</code> with a  
    110     link to the term in the document.""" 
    111     return re.sub(r"<code>" + spec_pre + r":(\w+)</code>", r"""<code><a href="#term_\1">""" + spec_pre + r""":\1</a></code>""", string)     
    112  
    113  
    114108def return_name(m, urinode): 
    115109    "Trims the namespace out of a term to give a name to the term." 
     
    147141        f = open("%s/%s.en" % (termdir, t), "r") 
    148142        doc = f.read() 
    149         doc = termlink(doc) 
     143        # replace <code>prefix:foo</code> with a link to foo in the document 
     144        doc = re.sub(r"<code>" + spec_pre + r":(\w+)</code>", 
     145                r"""<code><a href="#term_\1">""" + spec_pre + r""":\1</a></code>""", doc)     
    150146    except: 
    151147        return "" # "<p>No detailed documentation for this term.</p>" 
     
    260256    # Find subClassOf information 
    261257    o = m.find_statements( RDF.Statement(term, rdfs.subClassOf, None) ) 
     258    restrictions = [] 
    262259    if o.current(): 
    263260        superclasses = [] 
     
    267264                if (not uri in superclasses): 
    268265                    superclasses.append(uri) 
     266            else: 
     267                meta_types = m.find_statements(RDF.Statement(o.current().object, rdf.type, None)) 
     268                restrictions.append(meta_types.current().subject) 
     269 
    269270        if len(superclasses) > 0: 
    270271            doc += "<dt>Sub-class of</dt>" 
    271272            for superclass in superclasses: 
    272273                doc += "<dd>%s</dd>" % getTermLink(superclass) 
     274 
     275    for r in restrictions: 
     276        props = m.find_statements(RDF.Statement(r, None, None)) 
     277        onProp = None 
     278        comment = None 
     279        for p in props: 
     280            if p.predicate == owl.onProperty: 
     281                onProp = p.object 
     282            elif p.predicate == rdfs.comment: 
     283                comment = p.object 
     284        if onProp != None: 
     285            doc += '<div class="restriction"><dt>Restriction on property %s</dt><dd>' % getTermLink(onProp.uri) 
     286            if comment != None: 
     287                doc += "<p>%s</p>\n" % comment 
     288            props = m.find_statements(RDF.Statement(r, None, None)) 
     289            doc += "<dl>" 
     290            for p in props: 
     291                if p.predicate != owl.onProperty and p.predicate != rdfs.comment and not( 
     292                        p.predicate == rdf.type and p.object == owl.Restriction): 
     293                    doc += "<dt>%s</dt><dd>%s</dd>" % (getTermLink(p.predicate.uri), getTermLink(p.object.uri)) 
     294            doc += "</dl></dd></div>" 
    273295 
    274296    # Find out about properties which have rdfs:domain of t 
     
    307329            continue 
    308330        if p.predicate != last_pred: 
    309             doc += '<dt>%s</dt>\n' % niceName(str(p.predicate.uri)) 
     331            doc += '<dt>%s</dt>\n' % getTermLink(str(p.predicate.uri)) 
    310332        if p.object.is_resource(): 
    311333            doc += '<dd>%s</dd>\n' % getTermLink(str(p.object.uri), term, p.predicate) 
  • trunk/lv2specgen/template.html

    r2120 r2125  
    3232.subtitle { margin: 0; padding: 0; font-style: italic } 
    3333.index { padding: 1ex; border: dotted gray 2px; background-color: #eee; } 
     34.restriction { border: dotted 2px silver; padding: 0.5ex; margin-bottom: 0.25ex; } 
     35 
    3436 
    3537dl { padding: 0; margin: 0 } 
    36 dt { padding-top: 1ex; font-weight: bold } 
     38dt { font-weight: bold ; } 
     39dd { margin-bottom: 0.25ex; } 
    3740 
    3841hr {