示例#1
0
文件: model.py 项目: ShiZhan/seed
def gen_core():
    """generate SEED core model, the base import of all SEED node models."""

    SEED_LOG.info('creating core model ...')

    core = Graph()

    # core model base, prefix and namespace

    # setup prefix
    core.bind("rdf",   "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
    core.bind("rdfs",  "http://www.w3.org/2000/01/rdf-schema#")
    core.bind("xsd",   "http://www.w3.org/2001/XMLSchema#")
    core.bind("owl",   "http://www.w3.org/2002/07/owl#")
    core.bind("dc",    DC_URI)
    core.bind("terms", TERMS_URI)
    core.bind("seed",  SEED_URI)

    # setup base URI
    core.base = URIRef(SEED_BASE)

    # this is an OWL Ontology
    core.add((core.base, RDF.type,     OWL.Ontology))

    core.add((core.base, RDFS.comment, Literal('SEED ontology', lang='EN')))

    # Dublin Core Metadata
    core.add((core.base, DC.date,      Literal('2013-01-31')))
    core.add((core.base, DC.creator,   Literal('Shi.Zhan')))
    core.add((core.base, DC.created,
                Literal(time.strftime('%Y-%m-%d %H:%M:%S',
                            time.localtime(time.time())).encode('utf-8'),
                        datatype=XSD.dateTimeStamp)
            ))
    core.add((core.base, TERMS.license, Literal(LICENSE, datatype=XSD.string)))

    # use program version as model version, recording the origin of model.
    core.add((core.base, OWL.versionInfo,
        Literal(VERSION, datatype=XSD.hexBinary)))

    # setup default datatype
    core.add((XSD.anyType, RDF.type, RDFS.Datatype))

    # declare classes

    core.add((SEED.Object, RDF.type, OWL.Class))
    core.add((SEED.Bucket, RDF.type, OWL.Class))
    core.add((SEED.Bucket, RDFS.subClassOf, SEED.Object))
    core.add((SEED.SimpleObject, RDF.type, OWL.Class))
    core.add((SEED.SimpleObject, RDFS.subClassOf, SEED.Object))
    core.add((SEED.CompositeObject, RDF.type, OWL.Class))
    core.add((SEED.CompositeObject, RDFS.subClassOf, SEED.SimpleObject))
    core.add((SEED.Root, RDF.type, OWL.Class))
    core.add((SEED.Root, RDFS.subClassOf, SEED.Bucket))

    core.add((SEED.Bucket, OWL.disjointWith, SEED.SimpleObject))

    # declare and assign properties

    core.add((SEED.contain,    RDF.type, OWL.ObjectProperty))
    core.add((SEED.stripe,     RDF.type, OWL.ObjectProperty))
    core.add((SEED.replicate,  RDF.type, OWL.ObjectProperty))
    core.add((SEED.redundancy, RDF.type, OWL.ObjectProperty))

    core.add((SEED.name,      RDF.type, OWL.DatatypeProperty))
    core.add((SEED.origin,    RDF.type, OWL.DatatypeProperty))

    core.add((SEED.mode,      RDF.type, OWL.DatatypeProperty))
    core.add((SEED.ctime,     RDF.type, OWL.DatatypeProperty))
    core.add((SEED.mtime,     RDF.type, OWL.DatatypeProperty))
    core.add((SEED.atime,     RDF.type, OWL.DatatypeProperty))
    core.add((SEED.size,      RDF.type, OWL.DatatypeProperty))
    core.add((SEED.uid,       RDF.type, OWL.DatatypeProperty))
    core.add((SEED.gid,       RDF.type, OWL.DatatypeProperty))

    # Bucket contain only Object
    set_property(core, (SEED.Bucket, SEED.contain, SEED.Object), only=True)

    # CompositeObject [stripe, replicate, redundancy] only SimpleObject
    set_property(core, 
        (SEED.CompositeObject, SEED.stripe,     SEED.SimpleObject), only=True)
    set_property(core, 
        (SEED.CompositeObject, SEED.replicate,  SEED.SimpleObject), only=True)
    set_property(core, 
        (SEED.CompositeObject, SEED.redundancy, SEED.SimpleObject), only=True)

    # Object name
    set_property(core,
        (SEED.Object, SEED.name, XSD.normalizedString), max_qc=1)

    # Object origin
    set_property(core,
        (SEED.Object, SEED.origin, XSD.normalizedString), max_qc=1)

    # Object stat [mode, {c|m|a}time, length, size, uid, gid]
    set_property(core, (SEED.Object, SEED.mode,  XSD.unsignedShort), max_qc=1)
    set_property(core, (SEED.Object, SEED.ctime, XSD.unsignedLong),  max_qc=1)
    set_property(core, (SEED.Object, SEED.mtime, XSD.unsignedLong),  max_qc=1)
    set_property(core, (SEED.Object, SEED.atime, XSD.unsignedLong),  max_qc=1)
    set_property(core, (SEED.Object, SEED.size,  XSD.unsignedLong),  max_qc=1)
    set_property(core, (SEED.Object, SEED.uid,   XSD.int),           max_qc=1)
    set_property(core, (SEED.Object, SEED.gid,   XSD.int),           max_qc=1)

    # Serialize the store as RDF/XML to file.
    core.serialize(DEFAULT_CORE_MODEL)

    SEED_LOG.info("produced %d triples in %s." % \
        (len(core), DEFAULT_CORE_MODEL))