Skip to content

Commit

Permalink
Merge pull request #2 from danbri/sdo-itemlist
Browse files Browse the repository at this point in the history
Syncing from Dan's repository
  • Loading branch information
vholland committed Sep 15, 2014
2 parents 8dbb060 + e977868 commit 46bf57d
Show file tree
Hide file tree
Showing 22 changed files with 13,009 additions and 377 deletions.
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -25,6 +25,24 @@ interesting uses for it or have ideas for improvements.

See also wiki: https://github.com/rvguha/schemaorg/wiki/Contributing

Formats and standards
=====================

All schemas and examples are in data/ in utf-8 encoded files.

The main schemas file is data/schema.rdfa (utf-8)

While developing schemas, using data/sdo-somethinghere-schema.rdfa can be useful.

The format is based on W3C RDFS in HTML/RDFa format, see http://schema.org/docs/datamodel.html

The examples are stored in data/examples.txt (utf-8)

As with schemas, data/*examples.txt will also be read. It can be useful to develop
using separate files. When vocabulary is finally integrated into the main repository, schema
data will be merged into schema.org. However examples will stay in separate files, as this
works better with git's file comparison machinery.

Notes
=====

Expand Down
123 changes: 94 additions & 29 deletions api.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import webapp2
import jinja2
Expand All @@ -15,7 +16,7 @@
logging.basicConfig(level=logging.INFO) # dev_appserver.py --log_level debug .
log = logging.getLogger(__name__)

SCHEMA_VERSION=1.7
SCHEMA_VERSION=1.91

JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
Expand Down Expand Up @@ -105,19 +106,43 @@ def isDataType(self):
"""
return self.subClassOf(Unit.GetUnit("DataType"))

def superceded(self):
"""Has this property been superceded? (i.e. deprecated/archaic)"""
@staticmethod
def storePrefix(prefix):
"""Stores the prefix declaration for a given class or property"""
# Currently defined just to let the tests pass
pass

def superseded(self):
"""Has this property been superseded? (i.e. deprecated/archaic)"""
for triple in self.arcsOut:
if (triple.target != None and triple.arc.id == "supercededBy"):
if (triple.target != None and triple.arc.id == "supersededBy"):
return True
return False

def supercedes(self):
"""Returns a property that supercedes this one, or nothing."""
def supersedes(self):
"""Returns a property (assume max 1) that is supersededBy this one, or nothing."""
for triple in self.arcsIn:
if (triple.source != None and triple.arc.id == "supercededBy"):
if (triple.source != None and triple.arc.id == "supersededBy"):
return triple.source
return None
# TODO: supersedes is a list, e.g. 'seller' supersedes 'vendor', 'merchant'

def supersedes_all(self):
"""Returns a property (assume max 1) that is supersededBy this one, or nothing."""
newer = []
for triple in self.arcsIn:
if (triple.source != None and triple.arc.id == "supersededBy"):
newer.append(triple.source)
return newer

def supersededBy(self):
"""Returns a property (assume max 1) that supersededs this one, or nothing."""
for p in sorted(GetSources(Unit.GetUnit("typeOf"), Unit.GetUnit("rdf:Property")), key=lambda u: u.id):
allnewers = GetTargets(Unit.GetUnit("supersededBy"), p)
for newerprop in allnewers:
if self in newerprop.supersedes_all():
return newerprop # this is one of possibly many properties that supersedes self.
return None

def superproperties(self):
"""Returns super-properties of this one."""
Expand Down Expand Up @@ -339,7 +364,12 @@ def GetExtMappingsRDFa(node):
if len(equivs) > 0:
markup = ''
for c in equivs:
markup = markup + "<link property=\"owl:equivalentClass\" href=\"%s\"/>\n" % c.id

if (c.id.startswith('http')):
markup = markup + "<link property=\"owl:equivalentClass\" href=\"%s\"/>\n" % c.id
else:
markup = markup + "<link property=\"owl:equivalentClass\" resource=\"%s\"/>\n" % c.id

return markup
if (node.isAttribute()):
equivs = GetTargets(Unit.GetUnit("owl:equivalentProperty"), node)
Expand Down Expand Up @@ -406,6 +436,7 @@ def AddCachedText(self, node, textStrings):
"""
global PageCache
outputText = "".join(textStrings)
log.debug("CACHING: %s" % node.id)
PageCache[node.id] = outputText
return outputText

Expand Down Expand Up @@ -490,9 +521,10 @@ def ClassProperties (self, cl, subclass=False):
di = Unit.GetUnit("domainIncludes")
ri = Unit.GetUnit("rangeIncludes")
for prop in sorted(GetSources(di, cl), key=lambda u: u.id):
if (prop.superceded()):
if (prop.superseded()):
continue
supercedes = prop.supercedes()
supersedes = prop.supersedes()
olderprops = prop.supersedes_all()
inverseprop = prop.inverseproperty()
subprops = prop.subproperties()
superprops = prop.superproperties()
Expand All @@ -516,8 +548,9 @@ def ClassProperties (self, cl, subclass=False):
self.write("&nbsp;")
self.write("</td>")
self.write("<td class=\"prop-desc\" property=\"rdfs:comment\">%s" % (comment))
if (supercedes != None):
self.write(" Supercedes %s." % (self.ml(supercedes)))
if (len(olderprops) > 0):
olderlinks = ", ".join([self.ml(o) for o in olderprops])
self.write(" Supersedes %s." % olderlinks )
if (inverseprop != None):
self.write("<br/> Inverse property: %s." % (self.ml(inverseprop)))

Expand All @@ -533,9 +566,9 @@ def ClassIncomingProperties (self, cl):
di = Unit.GetUnit("domainIncludes")
ri = Unit.GetUnit("rangeIncludes")
for prop in sorted(GetSources(ri, cl), key=lambda u: u.id):
if (prop.superceded()):
if (prop.superseded()):
continue
supercedes = prop.supercedes()
supersedes = prop.supersedes()
inverseprop = prop.inverseproperty()
subprops = prop.subproperties()
superprops = prop.superproperties()
Expand All @@ -559,8 +592,8 @@ def ClassIncomingProperties (self, cl):
self.write("&nbsp;")
self.write("</td>")
self.write("<td class=\"prop-desc\">%s " % (comment))
if (supercedes != None):
self.write(" Supercedes %s." % (self.ml(supercedes)))
if (supersedes != None):
self.write(" Supersedes %s." % (self.ml(supersedes)))
if (inverseprop != None):
self.write("<br/> inverse property: %s." % (self.ml(inverseprop)) )

Expand All @@ -577,11 +610,15 @@ def AttributeProperties (self, node):
domains = sorted(GetTargets(di, node), key=lambda u: u.id)
first_range = True

supercedes = node.supercedes()
newerprop = node.supersededBy() # None of one. e.g. we're on 'seller'(new) page, we get 'vendor'(old)
olderprop = node.supersedes() # None or one
olderprops = node.supersedes_all() # list, e.g. 'seller' has 'vendor', 'merchant'.

inverseprop = node.inverseproperty()
subprops = node.subproperties()
superprops = node.superproperties()


if (inverseprop != None):
tt = "This means the same thing, but with the relationship direction reversed."
self.write("<p>Inverse-property: %s.</p>" % (self.ml(inverseprop, inverseprop.id,tt)) )
Expand Down Expand Up @@ -617,15 +654,35 @@ def AttributeProperties (self, node):
self.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(sbp, sbp.id, tt)))
self.write("\n</table>\n\n")

# Super-properties
if (len(superprops) > 0):
self.write("<table class=\"definition-table\">\n")
self.write(" <thead>\n <tr>\n <th>Super-properties</th>\n </tr>\n</thead>\n")
for spp in superprops:
c = GetComment(spp)
tt = "%s: ''%s''" % ( spp.id, c)
c = GetComment(spp) # markup needs to be stripped from c, e.g. see 'logo', 'photo'
c = re.sub(r'<[^>]*>', '', c) # This is not a sanitizer, we trust our input.
tt = "%s: ''%s''" % ( spp.id, c)
self.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(spp, spp.id, tt)))
self.write("\n</table>\n\n")

# Supersedes
if (len(olderprops) > 0):
self.write("<table class=\"definition-table\">\n")
self.write(" <thead>\n <tr>\n <th>Supersedes</th>\n </tr>\n</thead>\n")

for o in olderprops:
c = GetComment(o)
tt = "%s: ''%s''" % ( o.id, c)
self.write("\n <tr><td><code>%s</code></td></tr>\n" % (self.ml(o, o.id, tt)))
self.write("\n</table>\n\n")

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

def rep(self, markup):
"""Replace < and > with HTML escape chars."""
m1 = re.sub("<", "&lt;", markup)
Expand Down Expand Up @@ -827,14 +884,23 @@ def get(self, node):

def read_file (filename):
"""Read a file from disk, return it as a single string."""
import os.path
folder = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(folder, filename)
strs = []
for line in open(file_path, 'r').readlines():

file_path = full_path(filename)

import codecs
log.info("READING FILE: filename=%s file_path=%s " % (filename, file_path ) )
for line in codecs.open(file_path, 'r', encoding="utf8").readlines():
strs.append(line)
return "".join(strs)

def full_path(filename):
"""convert local file name to full path."""
import os.path
folder = os.path.dirname(os.path.realpath(__file__))
return os.path.join(folder, filename)


schemasInitialized = False

def read_schemas():
Expand All @@ -844,14 +910,13 @@ def read_schemas():
global schemasInitialized
if (not schemasInitialized):
files = glob.glob("data/*.rdfa")
schema_contents = []
file_paths = []
for f in files:
schema_content = read_file(f)
schema_contents.append(schema_content)
file_paths.append(full_path(f))

parser = parsers.MakeParserOfType('rdfa', None)
items = parser.parse(file_paths)

ft = 'rdfa'
parser = parsers.MakeParserOfType(ft, None)
items = parser.parse(schema_contents)
files = glob.glob("data/*examples.txt")
example_contents = []
for f in files:
Expand Down

0 comments on commit 46bf57d

Please sign in to comment.