IfcDoc.FormatOWL.FormatDefinitions C# (CSharp) Method

FormatDefinitions() public method

public FormatDefinitions ( DocProject docProject, DocObject>.Dictionary map, bool>.Dictionary included ) : string
docProject DocProject
map DocObject>.Dictionary
included bool>.Dictionary
return string
        public string FormatDefinitions(DocProject docProject, Dictionary<string, DocObject> map, Dictionary<DocObject, bool> included)
        {
            // clear containers
            listPropertiesOutput.Clear();
            addedIndividuals.Clear();
            attribInverses.Clear();
            subTypesOfEntity.Clear();

            StringBuilder sb = new StringBuilder();

            string ifcversion = "IFC4";
            // TO DO: customize the IFC version. In case of XSD, the piece of information (the full URL) is read from the .ifcdoc file

            //string ifcns = "http://www.buildingsmart-tech.org/ifcOWL/" + ifcversion;
            string ifcns = "http://ifcowl.openbimstandards.org/" + ifcversion;

            // namespace definitions
            sb.AppendLine("@prefix :      <" + ifcns + "#> .");
            sb.AppendLine("@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .");
            sb.AppendLine("@prefix dce:   <http://purl.org/dc/elements/1.1/> .");
            sb.AppendLine("@prefix owl:   <http://www.w3.org/2002/07/owl#> .");
            sb.AppendLine("@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .");
            sb.AppendLine("@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .");
            sb.AppendLine("@prefix vann:  <http://purl.org/vocab/vann/> .");
            sb.AppendLine("@prefix list:  <https://w3id.org/list#> .");
            sb.AppendLine("@prefix expr:  <https://w3id.org/express#> .");
            sb.AppendLine("@prefix ifc:   <" + ifcns + "#> .");
            sb.AppendLine("@prefix cc:    <http://creativecommons.org/ns#> .");
            sb.AppendLine("");

            // ontology definition
            sb.AppendLine("<" + ifcns + ">");
            sb.AppendLine("\ta                              owl:Ontology ;");
            sb.AppendLine("\trdfs:comment                   \"Ontology automatically generated from the EXPRESS schema using the IfcDoc functions developed by Pieter Pauwels ([email protected]) and Walter Terkaj ([email protected]) \" ;");
            sb.AppendLine("\tcc:license                     <http://creativecommons.org/licenses/by/3.0/> ;");
            sb.AppendLine("\tdce:contributor                \"Jakob Beetz ([email protected])\" , \"Maria Poveda Villalon ([email protected])\" ;"); // \"Aleksandra Sojic ([email protected])\" ,
            sb.AppendLine("\tdce:creator                    \"Pieter Pauwels ([email protected])\" , \"Walter Terkaj  ([email protected])\" ;");
            sb.AppendLine("\tdce:date                       \"2015/10/02\" ;");
            sb.AppendLine("\tdce:description                \"OWL ontology for the IFC conceptual data schema and exchange file format for Building Information Model (BIM) data\" ;");
            sb.AppendLine("\tdce:identifier                 \"" + ifcversion + "\" ;");
            sb.AppendLine("\tdce:language                   \"en\" ;");
            sb.AppendLine("\tdce:title                      \"" + ifcversion + "\" ;");
            sb.AppendLine("\tvann:preferredNamespacePrefix  \"ifc\" ;");
            sb.AppendLine("\tvann:preferredNamespaceUri     \"" + ifcns + "\" ;");
            sb.AppendLine("\towl:imports                    <https://w3id.org/express> .");
            sb.AppendLine();

            // check which Inverse Attributes must be discarded because of conflicts
            // get subtypes of an entity
            foreach (DocSection docSection in docProject.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        // get supertype/subtype
                        if (docEntity.BaseDefinition != null)
                        {
                            if (!subTypesOfEntity.ContainsKey(docEntity.BaseDefinition))
                                subTypesOfEntity.Add(docEntity.BaseDefinition, new HashSet<string>());
                            subTypesOfEntity[docEntity.BaseDefinition].Add(docEntity.Name);
                        }

                        // check attributes
                        foreach (DocAttribute docAttr in docEntity.Attributes)
                        {
                            if (docAttr.Inverse != null)
                            {
                                var key = new Tuple<string, string>(docAttr.Inverse, docAttr.DefinedType);
                                if (!attribInverses.ContainsKey(key))
                                    attribInverses.Add(key, 1);
                                else
                                    attribInverses[key] += 1;
                            }
                        }
                    }
                }
            }

            // generate definitions
            foreach (DocSection docSection in docProject.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocType docType in docSchema.Types)
                    {
                        bool use = false;
                        included.TryGetValue(docType, out use);

                        if (use)
                        {
                            if (docType is DocDefined)
                            {
                                DocDefined docDefined = (DocDefined)docType;
                                string text = this.FormatDefinedFull(docDefined, true);
                                sb.Append(text);
                            }
                            else if (docType is DocSelect)
                            {
                                DocSelect docSelect = (DocSelect)docType;
                                string text = this.FormatSelectFull(docSelect, map, included, true);
                                sb.Append(text);
                            }
                            else if (docType is DocEnumeration)
                            {
                                DocEnumeration docEnumeration = (DocEnumeration)docType;
                                string text = this.FormatEnumerationFull(docEnumeration, true);
                                sb.Append(text);
                            }
                        }
                    }

                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        bool use = false;
                        included.TryGetValue(docEntity, out use);

                        if (use)
                        {
                            string text = this.FormatEntityFull(docEntity, map, included, true);
                            sb.Append(text);
                        }
                    }
                }

            }
            listPropertiesOutput.Clear();
            return sb.ToString();
        }