Esempio n. 1
0
        public string BuildUpdateGql(Ontology thisOntology, /*Dictionary<string, string> dictInstances,*/ bool bUUIDHandling)
        {
            #region init vars
            StringBuilder sbUpdateGql = new StringBuilder("UPDATE ");
            bool bFirst = true;
            string strTripleListBeginLimiter = null;
            string strTripleObjectBeginLimiter = null;
            string strTripleObjectEndLimiter = null;
            string strTripleListEndLimiter = null;
            string strCompareAttString = null;
            #endregion

            sbUpdateGql.Append(GqlStringExtension.RemoveEvilCharacters(currentClass.ID));
            sbUpdateGql.Append(" SET (");

            foreach (string key in updateProperties.Keys)
            {
                OProperty currentProp = currentClass.GetProperty(key);

                if (currentProp == null)
                {
                    continue;
                }
                else
                {
                    bool bMultipleValues = true;
                    if (updateProperties[key].Count > 0)
                    {
                        #region prerequisites for value gql (pre/post limiter, data type specific handling)
                        switch (currentProp.Range /* currentTriple.Datatype */)
                        {
                            #region simple string types
                            case "string":
                            case "http://www.w3.org/2001/XMLSchema#string":
                            case "http://www.w3.org/2001/XMLSchema#date":
                            case "http://www.w3.org/2001/XMLSchema#anyURI":
                            #endregion
                            #region workaround simple types
                            case "http://dbpedia.org/datatype/valvetrain":
                            case "http://dbpedia.org/datatype/fuelType":
                            #endregion
                                #region set limiters
                                {
                                    strTripleListBeginLimiter = "'";
                                    strTripleObjectBeginLimiter = "";
                                    strTripleObjectEndLimiter = "";
                                    strTripleListEndLimiter = "'";
                                    bMultipleValues = false;
                                    break;
                                }
                                #endregion

                            #region simple number, etc. types
                            case "http://www.w3.org/2001/XMLSchema#integer":
                            case "http://www.w3.org/2001/XMLSchema#nonNegativeInteger":
                            case "http://www.w3.org/2001/XMLSchema#positiveInteger":
                            case "http://www.w3.org/2001/XMLSchema#double":
                            case "http://www.w3.org/2001/XMLSchema#float":
                            case "http://www.w3.org/2001/XMLSchema#gYear":
                            case "http://www.w3.org/2001/XMLSchema#boolean":
                            #endregion
                            #region dbpedia
                            case "http://dbpedia.org/datatype/squareKilometre":
                            case "http://dbpedia.org/datatype/squareMetre":
                            case "http://dbpedia.org/datatype/kilometrePerSecond":
                            case "http://dbpedia.org/datatype/kilometrePerHour":
                            case "http://dbpedia.org/datatype/kilogramPerCubicMetre":
                            case "http://dbpedia.org/datatype/gramPerKilometre":
                            case "http://dbpedia.org/datatype/day":
                            case "http://dbpedia.org/datatype/hour":
                            case "http://dbpedia.org/datatype/minute":
                            case "http://dbpedia.org/datatype/second":
                            case "http://dbpedia.org/datatype/cubicMetre":
                            case "http://dbpedia.org/datatype/cubicKilometre":
                            case "http://dbpedia.org/datatype/cubicCentimetre":
                            case "http://dbpedia.org/datatype/kilometre":
                            case "http://dbpedia.org/datatype/metre":
                            case "http://dbpedia.org/datatype/centimetre":
                            case "http://dbpedia.org/datatype/millimetre":
                            case "http://dbpedia.org/datatype/inhabitantsPerSquareKilometre":
                            case "http://dbpedia.org/datatype/kelvin":
                            case "http://dbpedia.org/datatype/cubicMetrePerSecond":
                            case "http://dbpedia.org/datatype/kilogram":
                            case "http://dbpedia.org/datatype/megabyte":
                            case "http://dbpedia.org/datatype/litre":
                            case "http://dbpedia.org/datatype/engineConfiguration":
                            case "http://dbpedia.org/datatype/kilowatt":
                            case "http://dbpedia.org/datatype/newtonMetre":
                            #endregion
                            #region currencies
                            case "http://dbpedia.org/datatype/usDollar":
                            case "http://dbpedia.org/datatype/euro":
                            case "http://dbpedia.org/datatype/bermudianDollar":
                            case "http://dbpedia.org/datatype/nicaraguanCórdoba":
                            case "http://dbpedia.org/datatype/poundSterling":
                            case "http://dbpedia.org/datatype/japaneseYen":
                            case "http://dbpedia.org/datatype/swedishKrona":
                            case "http://dbpedia.org/datatype/canadianDollar":
                            case "http://dbpedia.org/datatype/liberianDollar":
                            case "http://dbpedia.org/datatype/norwegianKrone":
                            case "http://dbpedia.org/datatype/namibianDollar":
                            case "http://dbpedia.org/datatype/ukrainianHryvnia":
                            case "http://dbpedia.org/datatype/czechKoruna":
                            case "http://dbpedia.org/datatype/swissFranc":
                            case "http://dbpedia.org/datatype/malaysianRinggit":
                            case "http://dbpedia.org/datatype/newZealandDollar":
                            case "http://dbpedia.org/datatype/danishKrone":
                            case "http://dbpedia.org/datatype/philippinePeso":
                            case "http://dbpedia.org/datatype/southKoreanWon":
                            case "http://dbpedia.org/datatype/hongKongDollar":
                            case "http://dbpedia.org/datatype/australianDollar":
                            case "http://dbpedia.org/datatype/indianRupee":
                            case "http://dbpedia.org/datatype/russianRouble":
                            case "http://dbpedia.org/datatype/singaporeDollar":
                            case "http://dbpedia.org/datatype/icelandKrona":
                            case "http://dbpedia.org/datatype/bosniaAndHerzegovinaConvertibleMarks":
                            case "http://dbpedia.org/datatype/polishZłoty":
                            case "http://dbpedia.org/datatype/latvianLats":
                            case "http://dbpedia.org/datatype/croatianKuna":
                            case "http://dbpedia.org/datatype/iranianRial":
                            case "http://dbpedia.org/datatype/egyptianPound":
                            case "http://dbpedia.org/datatype/lithuanianLitas":
                            case "http://dbpedia.org/datatype/pakistaniRupee":
                            case "http://dbpedia.org/datatype/bhutaneseNgultrum":
                            case "http://dbpedia.org/datatype/romanianNewLeu":
                            case "http://dbpedia.org/datatype/bangladeshiTaka":
                            case "http://dbpedia.org/datatype/nigerianNaira":
                            case "http://dbpedia.org/datatype/saudiRiyal":
                            case "http://dbpedia.org/datatype/brazilianReal":
                            case "http://dbpedia.org/datatype/turkishLira":
                            case "http://dbpedia.org/datatype/kazakhstaniTenge":
                            case "http://dbpedia.org/datatype/unitedArabEmiratesDirham":
                            case "http://dbpedia.org/datatype/mexicanPeso":
                            case "http://dbpedia.org/datatype/newTaiwanDollar":
                            case "http://dbpedia.org/datatype/hungarianForint":
                            case "http://dbpedia.org/datatype/falklandIslandsPound":
                            case "http://dbpedia.org/datatype/belizeDollar":
                            case "http://dbpedia.org/datatype/chileanPeso":
                            case "http://dbpedia.org/datatype/renminbi":
                            case "http://dbpedia.org/datatype/thaiBaht":
                            case "http://dbpedia.org/datatype/papuaNewGuineanKina":
                            case "http://dbpedia.org/datatype/kuwaitiDinar":
                            case "http://dbpedia.org/datatype/israeliNewSheqel":
                            case "http://dbpedia.org/datatype/sriLankanRupee":
                            case "http://dbpedia.org/datatype/peruvianNuevoSol":
                            case "http://dbpedia.org/datatype/estonianKroon":
                            case "http://dbpedia.org/datatype/southAfricanRand":
                            case "http://dbpedia.org/datatype/argentinePeso":
                            case "http://dbpedia.org/datatype/jamaicanDollar":
                            case "http://dbpedia.org/datatype/qatariRial":
                            #endregion
                                #region set limiter
                                {
                                    strTripleListBeginLimiter = "";
                                    strTripleObjectBeginLimiter = "";
                                    strTripleObjectEndLimiter = "";
                                    strTripleListEndLimiter = "";
                                    bMultipleValues = false;
                                    break;
                                }
                                #endregion
                            default:
                                #region set limiter
                                {
                                    if (bUUIDHandling)
                                    {
                                        strCompareAttString = "SETOFUUIDS(";
                                        strTripleListBeginLimiter = "SETOFUUIDS(";
                                        strTripleObjectBeginLimiter = "'";
                                        // strTripleObjectBeginLimiter = "REF(Name='";
                                        strTripleObjectEndLimiter = "'";
                                        strTripleListEndLimiter = ")";
                                    }
                                    else
                                    {
                                        strCompareAttString = "SETOF(";
                                        strTripleListBeginLimiter = "SETOF(";
                                        strTripleObjectBeginLimiter = "Name='";
                                        // strTripleObjectBeginLimiter = "REF(Name='";
                                        strTripleObjectEndLimiter = "'";
                                        strTripleListEndLimiter = ")";
                                    }
                                    bMultipleValues = true;
                                    break;
                                }
                                #endregion
                        }
                        #endregion

                        #region add values to sbUpdateValues
                        StringBuilder sbUpdateValues = new StringBuilder();
                        bool bFirstInList = true;
                        string newValue = null;
                        foreach (string value in updateProperties[key])
                        {
                            if (strTripleListBeginLimiter.Equals(strCompareAttString)
                                //&& !dictInstances.ContainsKey(value)
                                )
                                continue;

                            if (bFirstInList) bFirstInList = false;
                            else sbUpdateValues.Append(", ");

                            sbUpdateValues.Append(strTripleObjectBeginLimiter);

                            if (strTripleListBeginLimiter.Equals(strCompareAttString)
                                && value.Contains("__"))  // workaround for "__coord" workaround
                            {
                                newValue = value.Substring(0, value.IndexOf("__"));
                            }
                            else newValue = value;

                            if (currentProp.Range.Equals("http://www.w3.org/2001/XMLSchema#boolean"))
                            {
                                if (value.ToLower().Equals("true"))
                                    newValue = "1";
                                else newValue = "0";
                            }
                            else if (currentProp.Range.Contains("nteger"))  // integer workaround
                            {
                                if (value.Contains('.'))
                                    newValue = value.Substring(0, value.IndexOf('.'));
                            }
                            else
                                newValue = GqlStringExtension.ReplaceStringLimiter(newValue);

                            sbUpdateValues.Append(newValue);

                            sbUpdateValues.Append(strTripleObjectEndLimiter);

                            if (!bMultipleValues) break;
                        }
                        #endregion

                        #region add next attribute to sbUpdateGql (only if values are filled)
                        if (sbUpdateValues.Length > 0)
                        {
                            #region add key to gql (e.g. "Name=")
                            if (!bFirst)
                                sbUpdateGql.Append(", ");
                            else bFirst = false;

                            sbUpdateGql.Append(GqlStringExtension.RemoveEvilCharacters(key));
                            sbUpdateGql.Append("=");
                            #endregion
                            sbUpdateGql.Append(strTripleListBeginLimiter);
                            sbUpdateGql.Append(sbUpdateValues.ToString());
                            sbUpdateGql.Append(strTripleListEndLimiter);
                        }
                        #endregion

                    }
                }
            }

            if (bUUIDHandling)
            {
                sbUpdateGql.Append(") WHERE UUID = '");
            }
            else
            {
                sbUpdateGql.Append(") WHERE Name = '");
            }
            sbUpdateGql.Append(Subject);
            sbUpdateGql.Append("'");

            if (bFirst)
                return "";
            else
                return sbUpdateGql.ToString();
        }
        private static void CreateNodes(String filename, Ontology thisOntology, Dictionary<string, List<string>> dictExistingNodes,
            Dictionary<string, uint> dictDirectoryEntries, Dictionary<string, long> dictVertexIDs, Action<string> LogMessage, Action<string> LogError)
        {
            LogMessage("Begin CreateNodes(" + filename + ")");
            try
            {
                using (StreamReader srNodes = new StreamReader(filename))
                {
                    #region if input stream is empty --> do error handling
                    if (srNodes == null)
                    {
                        LogError("Error reading Nodes file: '" + filename + "'");
                        return;
                    }
                    #endregion

                    #region init local vars
                    int iCurrentLevel = -1;
                    int iCurrentTripleLevel = 0;
                    String strCurrentTriple;
                    Triple currentTriple = null;

                    Triple selectedTriple = null;

                    uint lineCount = 0;
                    uint instanceCount = 0;
                    #endregion

                    #region for each line
                    while ((strCurrentTriple = srNodes.ReadLine()) != null)
                    {
                        #region some debug info
                        if (lineCount % 100 == 0)
                        {
                            Console.Write(".");
                        }
                        if (lineCount % 10000 == 0)
                        {
                            LogMessage("CreateNodes: lineCount=" + lineCount + " instanceCount=" + instanceCount);
                            GC.Collect();
                            GC.Collect();
                        }
                        if (instanceCount > Properties.Settings.Default.InsertLimit)
                        {
                            LogMessage("Quit execution due to InsertLimit setting");
                            break;
                        }
                        lineCount++;
                        #endregion

                        currentTriple = NTripleParser.Split(strCurrentTriple, LogError);

                        #region some sample data for help
                        /* currentTriple.Subject               currentTriple.Predicate                           currentTriple.TripleObject
<http://dbpedia.org/resource/Autism> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<http://dbpedia.org/resource/Autism> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Disease> .
<http://dbpedia.org/resource/Alabama> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<http://dbpedia.org/resource/Alabama> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Place> .
<http://dbpedia.org/resource/Alabama> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/PopulatedPlace> .
<http://dbpedia.org/resource/Alabama> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/AdministrativeRegion> . 
                         */
                        #endregion

                        #region new concept: per uniqe subject, only one INSERT is done, the one with the highest level within the ontology
                        if (selectedTriple == null)
                            selectedTriple = currentTriple;

                        #region execute gql statement (includes redundancy check for several triple lines regarding one class (eg. Thing, Species, Animal, Mammal --> only mammal is inserted)
                        iCurrentTripleLevel = thisOntology.GetOClassLevel(currentTriple.TripleObject);
                        if (selectedTriple.Subject.Equals(currentTriple.Subject))
                        {
                            // check level 
                            if (iCurrentLevel < iCurrentTripleLevel)
                            {
                                // replace existing with new gql command
                                selectedTriple = currentTriple;
                                iCurrentLevel = iCurrentTripleLevel;
                            } // else do nothing 
                        }
                        else
                        {
                            if (!SaveTriple(selectedTriple, dictExistingNodes, dictDirectoryEntries, dictVertexIDs, LogError))
                            {
                                break;
                            }
                            instanceCount++;

                            // reset values
                            selectedTriple = currentTriple;
                            iCurrentLevel = iCurrentTripleLevel;
                        }
                        #endregion

                        #endregion

                    }  // end while
                    #endregion

                    #region finally - save last line
                    if (selectedTriple != null)
                    {
                        SaveTriple(selectedTriple, dictExistingNodes, dictDirectoryEntries, dictVertexIDs, LogError);
                    }
                    #endregion
                }
            }
            catch (Exception e)
            {
                LogError("Error creating instance file");
                LogError(e.Message);
                LogError(e.StackTrace);
            }
            LogMessage("End CreateNodes(" + filename + ")");
        }
        private static void EvaluateMappingbasedProperties(String filename, String lang, Dictionary<string, List<string>> dictExistingNodes, Dictionary<string, uint> dictDirectoryEntries, Ontology thisOntology, Action<string> LogMessage, Action<string> LogError)
        {
            LogMessage("Begin EvaluateMappingbasedProperties(" + filename + ", " + lang + ")");
            try
            {
                using (StreamReader srNodes = new StreamReader(filename))
                {
                    #region if input stream is empty --> do error handling
                    if (srNodes == null)
                    {
                        LogError("Error reading Nodes file: '" + filename + "'");
                        return;
                    }
                    #endregion

                    #region init local vars
                    ODataItem currentDataItem = null;
                    String strCurrentTriple;
                    Triple currentTriple;
                    uint lineCount = 0;
                    uint updateCount = 0;
                    #endregion

                    #region for each triple (line)
                    while ((strCurrentTriple = srNodes.ReadLine()) != null)
                    {

                        #region some debug info
                        /*
                        if (lineCount % 1000 == 0)
                        {
                            Console.Write(".");
                        }*/
                        if (lineCount % 100000 == 0)
                        {
                            LogMessage("EvaluateMappingbasedProperties('" + lang + "'): lineCount=" + lineCount + " updateCount=" + updateCount);
                            GC.Collect();
                            GC.Collect();
                        }
                        lineCount++;
                        #endregion

                        currentTriple = NTripleParser.Split(strCurrentTriple, LogError);

                        #region some sample data for help
                        /* currentTriple.Subject               currentTriple.Predicate                           currentTriple.TripleObject
                    <http://dbpedia.org/resource/Alabama> <http://xmlns.com/foaf/0.1/name> "State of Alabama"@en .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/demonym> "Alabamian or Alabaman"@en .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/capital> <http://dbpedia.org/resource/Montgomery%2C_Alabama> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/largestCity> <http://dbpedia.org/resource/Birmingham%2C_Alabama> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/areaTotal> "1.35765E11"^^<http://www.w3.org/2001/XMLSchema#double> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/areaLand> "1.31426E11"^^<http://www.w3.org/2001/XMLSchema#double> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/areaWater> "4.338E9"^^<http://www.w3.org/2001/XMLSchema#double> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/maximumElevation> "734.0"^^<http://www.w3.org/2001/XMLSchema#double> .
                    <http://dbpedia.org/resource/Alabama> <http://dbpedia.org/ontology/minimumElevation> "0.0"^^<http://www.w3.org/2001/XMLSchema#double> .                        
                        */
                        #endregion

                        #region clarify __coord> etc. handling
                        if (currentTriple.Subject.Contains("__"))
                        {
                            // TODO find better handling 
                            continue;
                        }
                        #endregion

                        if (currentDataItem == null)
                        {
                            #region create new ODataItem
                            if (CheckExistenceOfVertex(currentTriple.Subject, dictExistingNodes))
                            // if (!dictInstances.ContainsKey(currentTriple.Subject))
                            {
                                // Console.WriteLine("What's wrong here?");
                                // ignore uninserted data
                                currentDataItem = new ODataItem(new OClass("0815"));
                            }
                            else
                            {
                                // string instanceType = dictInstances[currentTriple.Subject];
                                string instanceType = GetVertexType(currentTriple.Subject, dictExistingNodes, LogError); // qr.FirstOrDefault().GetProperty<long>("TypeID"));
                                OClass instanceOClass = thisOntology.GetOClass(instanceType);
                                currentDataItem = instanceOClass.CreateODataItem();
                                currentDataItem.bToInsert = true;
                            }
                            currentDataItem.Subject = currentTriple.Subject;
                            #endregion
                        }
                        else
                        {
                            #region multiple rows can be aggregated to a single update statement (as long the currentSubject didn't change)
                            if (!currentTriple.Subject.Equals(currentDataItem.Subject))
                            {
                                #region save previous Instance - EXECUTE QUERY
                                if (CheckExistenceOfVertex(currentDataItem.Subject, dictExistingNodes)
                                    && !currentDataItem.IsEmpty())
                                {
                                    SaveODataItem(currentDataItem, dictExistingNodes, dictDirectoryEntries, lang, LogError);
                                    updateCount++;
                                }
                                #endregion

                                #region re-init all vars for next UPDATE ...  #region create new ODataItem
                                if (!CheckExistenceOfVertex(currentTriple.Subject, dictExistingNodes))
                                // !dictInstances.ContainsKey(currentTriple.Subject))
                                {
                                    // Console.WriteLine("What's wrong here?");
                                    // ignore uninserted data
                                    currentDataItem = new ODataItem(new OClass("0815"));
                                }
                                else
                                {

                                    string instanceType = GetVertexType(currentTriple.Subject, dictExistingNodes, LogError); //dictInstances[currentTriple.Subject];
                                    OClass instanceOClass = thisOntology.GetOClass(instanceType);
                                    currentDataItem = instanceOClass.CreateODataItem();
                                    currentDataItem.bToInsert = true;
                                }
                                currentDataItem.Subject = currentTriple.Subject;
                                #endregion
                            }
                            #endregion
                        }

                        #region temporary workaround - don't insert, when data had not been created before
                        if (!CheckExistenceOfVertex(currentTriple.Subject, dictExistingNodes)) // !dictInstances.ContainsKey(currentTriple.Subject))
                        {
                            continue;
                        }
                        #endregion

                        #region add current line to dictionary (or previously gql-string)
                        currentDataItem.Add(currentTriple.Predicate, currentTriple.TripleObject);

                        #endregion
                    }

                    #endregion

                    #region save last line
                    if (!currentDataItem.IsEmpty())
                    {
                        SaveODataItem(currentDataItem, dictExistingNodes, dictDirectoryEntries, lang, LogError);
                        updateCount++;
                    }
                    #endregion
                }  // using (StreamReader srNodes = new StreamReader(filename))
            }  // try
            catch (Exception e)
            {
                LogError("Error evaluating " + filename);
                LogError(e.Message);
                LogError(e.StackTrace);
            }
            LogMessage("End EvaluateMappingbasedProperties(" + filename + ", " + lang + ")");
        }
Esempio n. 4
0
        public static Ontology CreateOntologyFromXml(XmlElement eXmlRoot, Action<string> errorAction)
        {
            Ontology onti = null;
            XmlElement eRootElement = null;

            #region <rdf:RDF>
            try
            {
                eRootElement = eXmlRoot.getChildElements("rdf:RDF").First();                        // <rdf:RDF
                onti = new Ontology();
                onti.Xmlns = eRootElement.getAttribute("xmlns", onti.Xmlns).strValue;               //   xmlns = "http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#"
                onti.XmlBase = eRootElement.getAttribute("xml:base", onti.XmlBase).strValue;        //   xml:base = "http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl"
                onti.XmlnsRdf = eRootElement.getAttribute("xmlns:rdf", onti.XmlnsRdf).strValue;     //   xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                onti.XmlnsRdfs = eRootElement.getAttribute("xmlns:rdfs", onti.XmlnsRdfs).strValue;  //   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
                onti.XmlnsOwl = eRootElement.getAttribute("xmlns:owl", onti.XmlnsOwl).strValue;     //   xmlns:owl="http://www.w3.org/2002/07/owl#"
            }
            catch (Exception a) { }
            if (eRootElement == null)
            {
                if (errorAction != null)
                    errorAction("invalid structure: Missing root:element <rdf:RDF ..>");
                return onti;
            }
            #endregion

            #region <owl:ontology>
            try
            {
                XmlElement eOntology = eRootElement.getChildElements("owl:Ontology").First();  // <owl:Ontology
                onti.About = eOntology.getAttribute("rdf:about", onti.About).strValue;         //    rdf:about="">

                // not mandatory
                try
                {  // <rdfs:comment>An university ontology for benchmark tests</rdfs:comment>
                    onti.Comment = eOntology.getChildElements("rdfs:comment").First().getText(onti.Comment);
                }
                catch (Exception aa) { }

                // not mandatory
                try
                {  // <rdfs:label>Univ-bench Ontology</rdfs:label>
                    onti.Label = eOntology.getChildElements("rdfs:label").First().getText(onti.Label);
                }
                catch (Exception aa) { }

                // <owl:versionInfo>univ-bench-ontology-owl, ver April 1, 2004</owl:versionInfo>
                onti.VersionInfo = eOntology.getChildElements("owl:versionInfo").First().getText(onti.VersionInfo);
            }
            catch (Exception a)
            {
                if (errorAction != null)
                    errorAction("invalid structure: Missing param in <owl:ontology>." + a.Message + "\r\n" + a.StackTrace);
                return onti;
            }
            #endregion

            #region <owl:class>
            List<XmlElement> eClasses = eRootElement.getChildElements("owl:Class");
            OClass currentClass;
            String id;
            foreach (XmlElement xmlCurrentClass in eClasses)
            {
                try
                {
                    currentClass = new OClass();
                    try
                    {
                        currentClass.ID = xmlCurrentClass.getAttribute("rdf:ID", currentClass.ID).strValue;  // <owl:Class rdf:ID="AdministrativeStaff">
                    }
                    catch (Exception aa) { }

                    try
                    {
                        if (currentClass.ID == null)
                        {
                            currentClass.ID = xmlCurrentClass.getAttribute("rdf:about", currentClass.ID /*About*/).strValue; // <owl:Class rdf:about="http://dbpedia.org/ontology/Cycad">
                        }
                    }
                    catch (Exception aa) { }

                    if (currentClass.ID == null)
                    {
                        if (errorAction != null)
                            errorAction("Error adding <owl:class>: Missing rdf:ID or rdf:about. " + xmlCurrentClass);
                        continue;
                    }

                    try  // not mandatory: <rdfs:label>administrative staff worker</rdfs:label>
                    {
                        currentClass.Label = xmlCurrentClass.getChildElements("rdfs:label").First().getText(currentClass.Label);
                    }
                    catch (Exception aa) { }

                    try  // not mandatory: <rdfs:comment xml:lang="en">a group of sports teams that compete against each other in Cricket</rdfs:comment>
                    {
                        XmlElement eClassComment = xmlCurrentClass.getChildElements("rdfs:comment").First();
                        currentClass.Comment = eClassComment.getText(currentClass.Comment);
                        currentClass.CommentLang = eClassComment.getAttribute("xml:lang", currentClass.CommentLang).strValue;
                    }
                    catch (Exception aa) { }

                    try  // not mandatory : // <rdfs:subClassOf rdf:resource="#Employee" />
                    {
                        id = xmlCurrentClass
                            .getChildElements("rdfs:subClassOf").First()
                            .getAttribute("rdf:resource", "").strValue;

                        if (id.StartsWith("#"))   // ? todo clarify
                            id = id.Substring(1);

                        currentClass.IsSubClassOf = new OClass(id /*, id*/);
                    }
                    catch (Exception aa) { }

                    try
                    {
                        XmlElement eIntersection = xmlCurrentClass.getChildElements("owl:intersectionOf").First();  // <owl:intersectionOf rdf:parseType="Collection">
                        XmlElement eISectClass = eIntersection.getChildElements("owl:Class").First();               //   <owl:Class rdf:about="#Person" />
                        string strIsectAbout = eISectClass.getAttribute("rdf:about", "").strValue;
                        if (strIsectAbout.StartsWith("#"))
                            strIsectAbout = strIsectAbout.Substring(1);  // todo clarify
                        currentClass.IsSubClassOf = new OClass(/*null,*/ strIsectAbout);

                        OProperty odProp = new OProperty();
                        XmlElement eRestriction = eIntersection.getChildElements("owl:Restriction").First();        // <owl:Restriction>
                        XmlElement eOnProperty = eRestriction.getChildElements("owl:onProperty").First();           // <owl:onProperty rdf:resource="#headOf" />
                        odProp.ID = eOnProperty.getAttribute("rdf:resource", "").strValue;

                        XmlElement eSomeValuesFrom = eRestriction.getChildElements("owl:someValuesFrom").First();    // <owl:someValuesFrom>
                        XmlElement eValuesClass = eSomeValuesFrom.getChildElements("owl:Class").First();            // <owl:Class rdf:about="#Department" />
                        odProp.Domain = eValuesClass.getAttribute("rdf:about", "").strValue;
                        currentClass.AddDatatype(odProp);
                    }
                    catch (Exception aa) { }

                    if (!onti.AddOntologyClass(currentClass))
                    {
                        if (errorAction != null)
                            errorAction("Didn't add <owl:class> " + currentClass + " xml=" + xmlCurrentClass);
                        continue;
                    }
                    // onti.ValidateClasses();
                }
                catch (Exception a)
                {
                    Console.WriteLine("the following OntologyClass had not been imported due to errors.");
                    Console.WriteLine(xmlCurrentClass.ToString());
                    Console.WriteLine(a.Message);
                    Console.WriteLine(a.StackTrace);
                    Console.WriteLine();
                }
            }
            #endregion

            #region <owl:DatatypeProperty>
            List<XmlElement> lDatatypes = eRootElement.getChildElements("owl:DatatypeProperty");
            OProperty currentDatatype;
            foreach (XmlElement xmlCurrentElement in lDatatypes)
            {
                try
                {
                    currentDatatype = new OProperty();

                    try
                    {
                        currentDatatype.ID = xmlCurrentElement.getAttribute("rdf:ID", currentDatatype.ID).strValue;  // <owl:DatatypeProperty rdf:ID="age">
                    }
                    catch (Exception aa) { }

                    try
                    {
                        if (currentDatatype.ID == null)
                            currentDatatype.ID = xmlCurrentElement.getAttribute("rdf:about", currentDatatype.ID).strValue; // <owl:DatatypeProperty rdf:about="http://dbpedia.org/ontology/dateOfBurial">
                    }
                    catch (Exception aa) { }

                    if (currentDatatype.ID == null)
                    {
                        if (errorAction != null)
                            errorAction("Error adding <owl:DatatypeProperty>: Missing rdf:ID or rdf:about. " + xmlCurrentElement);
                        continue;
                    }

                    try
                    {
                        currentDatatype.Domain = xmlCurrentElement
                            .getChildElements("rdfs:domain").First()
                            .getAttribute("rdf:resource", currentDatatype.Domain).strValue;
                    }
                    catch (Exception a) { }

                    try  // not mandatory: <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"></rdfs:range>
                    {
                        // if (currentDatatype.Domain == null)
                        // {
                        currentDatatype.Range = xmlCurrentElement
                            .getChildElements("rdfs:range").First()
                            .getAttribute("rdf:resource", currentDatatype.Domain).strValue;
                        // }
                    }
                    catch (Exception aa) { }

                    /*
                    if (currentDatatype.Domain == null)
                    {
                        errorAction("Error adding <owl:DatatypeProperty>: Neither Range or Domain is set in xml:" + xmlCurrentElement);
                        continue;
                    }*/

                    try  // not mandatory: <rdfs:label>is age</rdfs:label>
                    {
                        currentDatatype.Label = xmlCurrentElement.getChildElements("rdfs:label").First().getText(currentDatatype.Label);
                    }
                    catch (Exception aa) { }

                    if (!onti.AddDatatype(currentDatatype))
                    {
                        if (errorAction != null)
                            errorAction("Didn't add <owl:DatatypeProperty> " + currentDatatype);
                        continue;
                    }
                    /*
                    else
                    {
                        Console.WriteLine("added datatype: " + currentDatatype.ToString());
                    }*/
                }
                catch (Exception a)
                {
                    Console.WriteLine("the following datatype had not been imported due to errors.");
                    Console.WriteLine(xmlCurrentElement.ToString());
                    Console.WriteLine(a.Message);
                    Console.WriteLine(a.StackTrace);
                    Console.WriteLine();
                }
            }
            #endregion

            #region <owl:ObjectProperty rdf:about="http://dbpedia.org/ontology/similar">
            List<XmlElement> lObjectProperties = eRootElement.getChildElements("owl:ObjectProperty");
            OProperty currentObjectProperty;
            foreach (XmlElement xmlCurrentObjectProperty in lObjectProperties)
            {
                try
                {
                    currentObjectProperty = new OProperty();

                    try
                    {
                        currentObjectProperty.ID = xmlCurrentObjectProperty.getAttribute("rdf:ID", currentObjectProperty.ID).strValue;  // <owl:ObjectProperty rdf:ID="degreeFrom">
                    }
                    catch (Exception aa) { }

                    try
                    {
                        if (currentObjectProperty.ID == null)
                        {
                            currentObjectProperty.ID = xmlCurrentObjectProperty.getAttribute("rdf:about", currentObjectProperty.ID).strValue; // <owl:ObjectProperty rdf:about="http://dbpedia.org/ontology/similar">
                        }
                    }
                    catch (Exception aa) { }

                    if (currentObjectProperty.ID == null)
                    {
                        if (errorAction != null)
                            errorAction("Error adding <owl:ObjectProperty>: Missing rdf:ID or rdf:about. " + xmlCurrentObjectProperty);
                        continue;
                    }

                    try
                    {
                        currentObjectProperty.Domain = xmlCurrentObjectProperty
                            .getChildElements("rdfs:domain").First()
                            .getAttribute("rdf:resource", currentObjectProperty.Domain).strValue;
                    }
                    catch (Exception aa)
                    {
                        if (errorAction != null)
                            errorAction("Error adding ObjectProperty: <rdfs:domain> is not set in xml:" + xmlCurrentObjectProperty);
                        continue;
                    }

                    try
                    {
                        currentObjectProperty.Range = xmlCurrentObjectProperty
                            .getChildElements("rdfs:range").First()
                            .getAttribute("rdf:resource", currentObjectProperty.Range).strValue;
                    }
                    catch (Exception aa)
                    {
                        if (errorAction != null)
                            errorAction("Error adding ObjectProperty: <rdfs:range> is not set in xml:" + xmlCurrentObjectProperty);
                        continue;
                    }

                    try  // not mandatory: <rdfs:label>is age</rdfs:label>
                    {
                        currentObjectProperty.Label = xmlCurrentObjectProperty.getChildElements("rdfs:label").First().getText(currentObjectProperty.Label);
                    }
                    catch (Exception aa) { }

                    try  // not mandatory: <owl:inverseOf rdf:resource="#hasAlumnus"/>
                    {
                        currentObjectProperty.InverseOf = xmlCurrentObjectProperty.getChildElements("rdfs:label").First().getText(currentObjectProperty.InverseOf);
                    }
                    catch (Exception aa) { }

                    try  // not mandatory: <rdfs:subPropertyOf rdf:resource="#memberOf" />
                    {
                        currentObjectProperty.SubPropertyOf = xmlCurrentObjectProperty
                            .getChildElements("rdfs:subPropertyOf").First()
                            .getAttribute("", currentObjectProperty.SubPropertyOf).strValue;
                    }
                    catch (Exception aa) { }

                    if (!onti.AddObjectProperty(currentObjectProperty))
                    {
                        if (errorAction != null)
                            errorAction("Didn't add <owl:ObjectProperty> " + currentObjectProperty);
                    }
                }
                catch (Exception a)
                {
                    Console.WriteLine("the following ObjectProperty had not been imported due to errors.");
                    Console.WriteLine(xmlCurrentObjectProperty.ToString());
                    Console.WriteLine(a.Message);
                    Console.WriteLine(a.StackTrace);
                    Console.WriteLine();
                }
            }
            #endregion

            return onti;
        }