def cctsdoc(self, e, name): '''Return the CCTS documentation named name from the element e.''' doc = e.find(XSD.xml("annotation") + "/" + XSD.xml("documentation") + "//" + CCTS.xml(name)) if doc is None: return None return doc.text
def convert_basic(self, g): '''Convert basic components.''' root = self.openxsd("common", "UBL-CommonBasicComponents-2.1.xsd") for e in root.findall(XSD.xml('element')): t = root.find(XSD.xml("complexType") + "[@name='" + e.attrib['type'] + "']") datatype = t.find(XSD.xml("simpleContent") + "/" + XSD.xml("extension")).attrib['base'] uri = self.attriburi("cbc:" + e.attrib['name']) g.add((uri, RDF.type, MDR.Property)) g.add((uri, MDR.context, URIRef(self.ns))) g.add((uri, DCTERMS.rights, RIGHTS)) g.add((uri, DCTERMS.rightsHolder, RIGHTS_HOLDER)) g.add((uri, ADMS.representationTechnique, XMLSchema)) g.add((uri, MDR.hasXMLNamespace, URIRef(CBC))) g.add((uri, MDR.hasXMLLocalPart, Literal(e.attrib['name']))) g.add((uri, MDR.representation, self.attriburi(datatype)))
def convert_maindocs(self, g): '''Convert documents (extract property information).''' for filename in self.listdir("maindoc"): root = self.openxsd("maindoc", filename) for e in root.findall(XSD.xml('complexType') + "/" + XSD.xml('sequence') + "/" + XSD.xml('element')): if e.attrib['ref'].startswith("ext:"): continue propuri = self.attriburi(e.attrib['ref']) g.add((propuri, MDR.propertyTerm, Literal(self.cctsdoc(e, "PropertyTerm")))) propqualifier = self.cctsdoc(e, "PropertyTermQualifier") if propqualifier: g.add((propuri, MDR.propertyTermQualifier, Literal(propqualifier))) dtqualifier = self.cctsdoc(e, "DataTypeQualifier") if dtqualifier: g.add((propuri, MDR.representationQualifier, Literal(dtqualifier)))
def convert_datatypes(self, g): '''Convert data types.''' root = self.openxsd("common", "UBL-UnqualifiedDataTypes-2.1.xsd") for e in root.findall(XSD.xml('complexType')): uri = self.attriburi("udt:" + e.attrib['name']) g.add((uri, RDF.type, MDR.DataType)) g.add((uri, MDR.context, URIRef(self.ns))) g.add((uri, DCTERMS.rights, RIGHTS)) g.add((uri, DCTERMS.rightsHolder, RIGHTS_HOLDER)) g.add((uri, SKOS.definition, self.text(self.cctsdoc(e, "Definition")))) g.add((uri, MDR.representationTerm, Literal(self.cctsdoc(e, "RepresentationTermName")))) g.add((uri, ADMS.representationTechnique, XMLSchema)) g.add((uri, MDR.hasXMLNamespace, URIRef(UDT))) g.add((uri, MDR.hasXMLLocalPart, Literal(e.attrib['name'])))
def convert_aggregate(self, g): '''Convert aggregate components.''' root = self.openxsd("common", "UBL-CommonAggregateComponents-2.1.xsd") for e in root.findall(XSD.xml('element')): uri = self.attriburi("cac:" + e.attrib['name']) g.add((uri, RDF.type, MDR.Property)) g.add((uri, MDR.context, URIRef(self.ns))) g.add((uri, DCTERMS.rights, RIGHTS)) g.add((uri, DCTERMS.rightsHolder, RIGHTS_HOLDER)) g.add((uri, ADMS.representationTechnique, XMLSchema)) g.add((uri, MDR.hasXMLNamespace, URIRef(CAC))) g.add((uri, MDR.hasXMLLocalPart, Literal(e.attrib['name']))) g.add((uri, MDR.representation, self.attriburi("cac:" + e.attrib['type']))) # Property terms are defined below and in convert_maindocs for cls in root.findall(XSD.xml('complexType')): clsuri = self.attriburi("cac:" + cls.attrib['name']) clsubl = re.sub(r"Type$", r"", cls.attrib['name']) clsname = self.cctsdoc(cls, "ObjectClass") # Object class g.add((clsuri, RDF.type, MDR.ObjectClass)) g.add((clsuri, MDR.context, URIRef(self.ns))) g.add((clsuri, DCTERMS.rights, RIGHTS)) g.add((clsuri, DCTERMS.rightsHolder, RIGHTS_HOLDER)) g.add((clsuri, ADMS.representationTechnique, XMLSchema)) g.add((clsuri, MDR.hasXMLNamespace, URIRef(CAC))) g.add((clsuri, MDR.hasXMLLocalPart, Literal(cls.attrib['name']))) g.add((clsuri, RDFS.label, self.text(clsname))) g.add((clsuri, MDR.objectClassName, Literal(clsname))) g.add((clsuri, SKOS.definition, self.text(self.cctsdoc(cls, "Definition")))) for i, e in enumerate(cls.findall(XSD.xml('sequence') + "/" + XSD.xml('element'))): propuri = self.attriburi(e.attrib['ref']) propubl = re.sub(r"^[^:]*:", r"", e.attrib['ref']) uri = self.uri("element", clsubl + propubl) # Data Element g.add((uri, RDF.type, MDR.DataElement)) g.add((uri, MDR.context, URIRef(self.ns))) g.add((uri, DCTERMS.rights, RIGHTS)) g.add((uri, DCTERMS.rightsHolder, RIGHTS_HOLDER)) g.add((uri, ADMS.representationTechnique, XMLSchema)) g.add((uri, MDR.objectClass, clsuri)) g.add((uri, MDR.property, propuri)) g.add((uri, SKOS.definition, self.text(self.cctsdoc(e, "Definition")))) g.add((uri, MDR.order, self.integer(i + 1))) example = self.cctsdoc(e, "Examples") if example: g.add((uri, MDR.example, Literal(example))) cardmin = int(e.attrib['minOccurs']) if cardmin != 0: g.add((uri, MDR.minCardinality, self.nonneg(cardmin))) cardmax = e.attrib['maxOccurs'] if cardmax != "unbounded": g.add((uri, MDR.maxCardinality, self.nonneg(int(cardmax)))) # Property g.add((propuri, MDR.propertyTerm, Literal(self.cctsdoc(e, "PropertyTerm")))) propqualifier = self.cctsdoc(e, "PropertyTermQualifier") if propqualifier: g.add((propuri, MDR.propertyTermQualifier, Literal(propqualifier))) dtqualifier = self.cctsdoc(e, "DataTypeQualifier") if dtqualifier: g.add((propuri, MDR.representationQualifier, Literal(dtqualifier)))