Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix1166 - RDFa output fixes into Master #1211

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,16 @@ def isDataType(self, layers='core'):
return self.typeFlags['d']

ret = False
if (self.directInstanceOf(Unit.GetUnit("DataType"), layers=layers)):
if (self.directInstanceOf(Unit.GetUnit("DataType"), layers=layers) or
self.id == "DataType"):
ret = True
else:
subs = GetTargets(Unit.GetUnit("rdf:type"), self, layers=layers)
subs += GetTargets(Unit.GetUnit("rdfs:subClassOf"), self, layers=layers)
subs = GetTargets(Unit.GetUnit("rdfs:subClassOf"), self, layers=layers)

for p in subs:
if p.isDataType(layers=layers):
ret = True
break

self.typeFlags['d'] = ret
return ret

Expand Down
74 changes: 47 additions & 27 deletions sdoapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,21 @@ def ml(self, node, label='', title='', prop='', hashorslash='/'):
* title = optional title attribute on the link
* prop = an optional property value to apply to the A element
"""
if(node.id == "DataType"): #Special case
return "<a href=\"%s\">%s</a>" % (node.id, node.id)

if label=='':
label = node.id
if title != '':
title = " title=\"%s\"" % (title)
if prop:
prop = " property=\"%s\"" % (prop)

rdfalink = ''
if prop:
rdfalink = '<link %s href="http://schema.org/%s" />' % (prop,label)

if(node.id == "DataType"): #Special case
return "%s<a href=\"%s\">%s</a>" % (rdfalink,node.id, node.id)

urlprefix = ""
home = node.getHomeLayer()

Expand All @@ -490,9 +496,6 @@ def ml(self, node, label='', title='', prop='', hashorslash='/'):
extflag = EXTENSION_SUFFIX
tooltip = "title=\"Defined in extension: %s.schema.org\" " % home

rdfalink = ''
if prop:
rdfalink = '<link %s href="http://schema.org/%s" />' % (prop,label)


return "%s<a %s %s href=\"%s%s%s\"%s>%s</a>%s" % (rdfalink,tooltip, extclass, urlprefix, hashorslash, node.id, title, label, extflag)
Expand All @@ -510,9 +513,9 @@ def makeLinksFromArray(self, nodearray, tooltip=''):

def emitUnitHeaders(self, node, layers='core'):
"""Write out the HTML page headers for this node."""
self.write("<h1 property=\"rdfs:label\" class=\"page-title\">\n")
self.write("<h1 property=\"rdfs:label\" class=\"page-title\">")
self.write(node.id)
self.write("</h1>")
self.write("</h1>\n")
home = node.home
if home != "core" and home != "":
self.write("Defined in the %s.schema.org extension.<br/>" % home)
Expand Down Expand Up @@ -545,6 +548,9 @@ def BreadCrumbs(self, node, layers):
if (node.isAttribute(layers=layers)):
cstack.append(Unit.GetUnit("Property"))
cstack.append(Unit.GetUnit("Thing"))
elif(node.isDataType(layers=layers) and node.id != "DataType"):
cstack.append(Unit.GetUnit("DataType"))


enuma = node.isEnumerationValue(layers=layers)

Expand All @@ -555,16 +561,26 @@ def BreadCrumbs(self, node, layers):
continue
count = 0
while(len(self.crumbStacks[row]) > 0):
propertyval = None
n = self.crumbStacks[row].pop()

if((len(self.crumbStacks[row]) == 1) and
not ":" in n.id) : #penultimate crumb that is not a non-schema reference
if node.isAttribute(layers=layers):
if n.isAttribute(layers=layers): #Can only be a subproperty of a property
propertyval = "rdfs:subPropertyOf"
else:
propertyval = "rdfs:subClassOf"

if(count > 0):
if((len(self.crumbStacks[row]) == 0) and enuma):
if((len(self.crumbStacks[row]) == 0) and enuma): #final crumb
thisrow += " :: "
else:
thisrow += " &gt; "
elif n.id == "Class": # If Class is first breadcrum suppress it
continue
count += 1
thisrow += "%s" % (self.ml(n))
thisrow += "%s" % (self.ml(n,prop=propertyval))
crumbsout.append(thisrow)

self.write("<h4>")
Expand All @@ -587,7 +603,7 @@ def WalkCrumbs(self, node, cstack, layers):
subs = []

if(node.isDataType(layers=layers)):
subs = GetTargets(Unit.GetUnit("rdf:type"), node, layers=layers)
#subs = GetTargets(Unit.GetUnit("rdf:type"), node, layers=layers)
subs += GetTargets(Unit.GetUnit("rdfs:subClassOf"), node, layers=layers)
elif node.isClass(layers=layers):
subs = GetTargets(Unit.GetUnit("rdfs:subClassOf"), node, layers=layers)
Expand Down Expand Up @@ -653,11 +669,12 @@ def ClassProperties (self, cl, subclass=False, layers="core", out=None, hashorsl
subprops = sorted(prop.subproperties(layers=layers),key=lambda u: u.id)
superprops = sorted(prop.superproperties(layers=layers),key=lambda u: u.id)
ranges = sorted(GetTargets(ri, prop, layers=layers),key=lambda u: u.id)
doms = sorted(GetTargets(di, prop, layers=layers), key=lambda u: u.id)
comment = GetComment(prop, layers=layers)
if (not headerPrinted):
class_head = self.ml(cl)
if subclass:
class_head = self.ml(cl, prop="rdfs:subClassOf")
class_head = self.ml(cl)
out.write("<tr class=\"supertype\">\n <th class=\"supertype-name\" colspan=\"3\">Properties from %s</th>\n \n</tr>\n\n<tbody class=\"supertype\">\n " % (class_head))
headerPrinted = True

Expand All @@ -670,6 +687,8 @@ def ClassProperties (self, cl, subclass=False, layers="core", out=None, hashorsl
first_range = False
out.write(self.ml(r, prop='rangeIncludes'))
out.write("&nbsp;")
for d in doms:
out.write("<link property=\"domainIncludes\" href=\"http://schema.org/%s\">" % d.id)
out.write("</td>")
out.write("<td class=\"prop-desc\" property=\"rdfs:comment\">%s" % (comment))
if (len(olderprops) > 0):
Expand All @@ -683,7 +702,7 @@ def ClassProperties (self, cl, subclass=False, layers="core", out=None, hashorsl
propcount += 1

if subclass: # in case the superclass has no defined attributes
out.write("<tr><td colspan=\"3\"><meta property=\"rdfs:subClassOf\" content=\"%s\"></td></tr>" % (cl.id))
out.write("<tr><td colspan=\"3\"></td></tr>")

return propcount

Expand Down Expand Up @@ -765,7 +784,6 @@ def _ClassExtensionProperties (self, out, cl, layers="core"):
exts[ext].append(prop)

for e in sorted(exts.keys()):
log.info("%s EXTS %s: %s" % (cl, e,exts[e]))
count = 0
first = True
for p in sorted(exts[e], key=lambda u: u.id):
Expand Down Expand Up @@ -934,24 +952,24 @@ def emitAttributeProperties(self, node, layers="core", out=None, hashorslash="/"
out.write("\n <code>%s</code> - %s" % (self.ml(d, d.id, tt, prop="domainIncludes",hashorslash=hashorslash),defin ))
out.write(" </td>\n </tr>\n</table>\n\n")

# Sub-properties
if (subprops != None and len(subprops) > 0):
out.write("<table class=\"definition-table\">\n")
out.write(" <thead>\n <tr>\n <th>Sub-properties</th>\n </tr>\n</thead>\n")
for sbp in subprops:
c = ShortenOnSentence(StripHtmlTags( GetComment(sbp,layers=layers) ),60)
tt = "%s: ''%s''" % ( sbp.id, c)
out.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(sbp, sbp.id, tt, hashorslash=hashorslash)))
for sp in subprops:
c = ShortenOnSentence(StripHtmlTags( GetComment(sp,layers=layers) ),60)
tt = "%s: ''%s''" % ( sp.id, c)
out.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(sp, sp.id, tt, hashorslash=hashorslash)))
out.write("\n</table>\n\n")

# Super-properties
if (superprops != None and len(superprops) > 0):
out.write("<table class=\"definition-table\">\n")
out.write(" <thead>\n <tr>\n <th>Super-properties</th>\n </tr>\n</thead>\n")
for spp in superprops:
c = ShortenOnSentence(StripHtmlTags( GetComment(spp,layers=layers) ),60)
c = re.sub(r'<[^>]*>', '', c) # This is not a sanitizer, we trust our input.
tt = "%s: ''%s''" % ( spp.id, c)
out.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(spp, spp.id, tt,hashorslash)))
for sp in superprops:
c = ShortenOnSentence(StripHtmlTags( GetComment(sp,layers=layers) ),60)
tt = "%s: ''%s''" % ( sp.id, c)
out.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(sp, sp.id, tt, hashorslash=hashorslash)))
out.write("\n</table>\n\n")

self.emitSupersedes(node,layers=layers,out=out,hashorslash=hashorslash)
Expand All @@ -962,7 +980,7 @@ def emitSupersedes(self, node, layers="core", out=None, hashorslash="/"):
if not out:
out = self
newerprop = node.supersededBy(layers=layers) # None of one. e.g. we're on 'seller'(new) page, we get 'vendor'(old)
olderprop = node.supersedes(layers=layers) # None or one
#olderprop = node.supersedes(layers=layers) # None or one
olderprops = sorted(node.supersedes_all(layers=layers),key=lambda u: u.id) # list, e.g. 'seller' has 'vendor', 'merchant'.


Expand All @@ -972,17 +990,19 @@ def emitSupersedes(self, node, layers="core", out=None, hashorslash="/"):
out.write(" <thead>\n <tr>\n <th>Supersedes</th>\n </tr>\n</thead>\n")

for o in olderprops:
c = GetComment(o, layers=layers)
c = ShortenOnSentence(StripHtmlTags( GetComment(o,layers=layers) ),60)
tt = "%s: ''%s''" % ( o.id, c)
out.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(o, o.id, tt, hashorslash)))
out.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(o, o.id, tt)))
log.info("Super %s" % o.id)
out.write("\n</table>\n\n")

# supersededBy (at most one direct successor)
if (newerprop != None):
out.write("<table class=\"definition-table\">\n")
out.write(" <thead>\n <tr>\n <th><a href=\"/supersededBy\">supersededBy</a></th>\n </tr>\n</thead>\n")
tt="supersededBy: %s" % newerprop.id
out.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(newerprop, newerprop.id, tt,hashorslash)))
c = ShortenOnSentence(StripHtmlTags( GetComment(newerprop,layers=layers) ),60)
tt = "%s: ''%s''" % ( newerprop.id, c)
out.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(newerprop, newerprop.id, tt)))
out.write("\n</table>\n\n")

def rep(self, markup):
Expand Down