Пример #1
0
        private void AddProperties(CompileUnitOption compileUnitOption)
        {
            IEnumerable <OntologyClass> fullClassContext = null;

            if (this.ontologyClass.SuperClasses.Any())
            {
                fullClassContext = this.ontologyClass.SuperClasses
                                   .Union(this.ontologyClass.SuperClasses
                                          .SelectMany(sc => sc.SubClasses));
            }
            else
            {
                fullClassContext = new OntologyClass[] { this.ontologyClass }
                .Union(this.ontologyClass.SubClasses);
            }
            HashSet <string> classes = new HashSet <string>();

            foreach (var contextClass in fullClassContext)
            {
                if (classes.Contains(contextClass.ToPascalCase()) == false)
                {
                    this.AddPropertiesFrom(contextClass, compileUnitOption);
                    classes.Add(contextClass.ToPascalCase());
                }
            }
        }
        public static IEnumerable <INode> AsEnumeration(this OntologyClass oClass)
        {
            INode oneOf = oClass.Graph.CreateUriNode(VocabularyHelper.OWL.oneOf);
            INode list  = oClass.EquivalentClasses.Append(oClass).SelectMany(equiv => equiv.GetNodesViaPredicate(oneOf)).First();

            return(oClass.Graph.GetListItems(list));
        }
Пример #3
0
        public void TestDeserializationFromJson()
        {
            String     jsonSerialization     = "{\"generated\":\"20171016_081513\",\"version\":2,\"ontologyInfo\":{\"prefixes\":[{\"prefix\":\"http://www.w3.org/2001/XMLSchema\",\"prefixId\":\"1\"},{\"prefix\":\"http://kdl.ge.com/batterydemo\",\"prefixId\":\"0\"}],\"propertyList\":[{\"comments\":[\"no note neither\",\"second non-note\"],\"domain\":[\"0:Battery\"],\"range\":[\"1:string\"],\"fullUri\":\"0:name\",\"labels\":[\"I got nothing\"]},{\"comments\":[],\"domain\":[\"0:Cell\"],\"range\":[\"1:string\"],\"fullUri\":\"0:cellId\",\"labels\":[\"cell identifier\"]},{\"comments\":[],\"domain\":[\"0:Battery\",\"0:Cell\"],\"range\":[\"1:string\"],\"fullUri\":\"0:id\",\"labels\":[\"alias added by Battery\",\"alias added by Cell\"]}, {\"comments\":[],\"domain\":[\"0:BatteryChild\"],\"range\":[\"1:int\"],\"fullUri\":\"0:tantrumsPerDay\",\"labels\":[]},{\"comments\":[\"you know,like red\"],\"domain\":[\"0:Cell\"],\"range\":[\"0:Color\"],\"fullUri\":\"0:color\",\"labels\":[]},{\"comments\":[],\"domain\":[\"0:Battery\"],\"range\":[\"0:Cell\"],\"fullUri\":\"0:cell\",\"labels\":[]}],\"enumerations\":[{\"fullUri\":\"0:Color\",\"enumeration\":[\"0:blue\",\"0:white\",\"0:red\"]}],\"classList\":[{\"comments\":[],\"subClasses\":[\"0:BatteryChild\"],\"directConnections\":[{\"destinationClass\":\"0:Cell\",\"predicate\":\"0:cell\",\"startClass\":\"0:Battery\"}],\"fullUri\":\"0:Battery\",\"superClasses\":[],\"labels\":[\"duracell\"]},{\"comments\":[],\"subClasses\":[],\"directConnections\":[{\"destinationClass\":\"0:Color\",\"predicate\":\"0:color\",\"startClass\":\"0:Cell\"},{\"destinationClass\":\"0:Cell\",\"predicate\":\"0:cell\",\"startClass\":\"0:Battery\"},{\"destinationClass\":\"0:Cell\",\"predicate\":\"0:cell\",\"startClass\":\"0:BatteryChild\"}],\"fullUri\":\"0:Cell\",\"superClasses\":[],\"labels\":[]},{\"comments\":[],\"subClasses\":[],\"directConnections\":[{\"destinationClass\":\"0:Cell\",\"predicate\":\"0:cell\",\"startClass\":\"0:BatteryChild\"}],\"fullUri\":\"0:BatteryChild\",\"superClasses\":[\"0:Battery\"],\"labels\":[]},{\"comments\":[],\"subClasses\":[],\"directConnections\":[{\"destinationClass\":\"0:Color\",\"predicate\":\"0:color\",\"startClass\":\"0:Cell\"}],\"fullUri\":\"0:Color\",\"superClasses\":[],\"labels\":[]}]}}";
            JsonObject serializedOInfoObject = JsonObject.Parse(jsonSerialization);

            OntologyInfo oInfo = new OntologyInfo();

            oInfo.AddJson(serializedOInfoObject);

            Assert.IsTrue(oInfo != null);

            // check the actual content.
            int classCount = oInfo.GetNumberOfClasses();
            int propCount  = oInfo.GetNumberOfProperties();
            int enumCount  = oInfo.GetNumberOfEnum();

            // how are the counts?
            Assert.IsTrue(enumCount == 1);
            Assert.IsTrue(propCount == 6);
            Assert.IsTrue(classCount == 4);

            // check the domain of a property
            OntologyClass           batt      = oInfo.GetClass("http://kdl.ge.com/batterydemo#Battery");
            List <OntologyProperty> battProps = batt.GetProperties();

            Assert.IsTrue(battProps.Count == 3);
        }
Пример #4
0
 public Result(String name, ResultType type, OntologyClass reference = null)
 {
     _name      = name;
     _type      = type;
     _rules     = new Dictionary <string, Rule>();
     _reference = reference;
 }
Пример #5
0
 public Result()
 {
     _name      = "newresult";
     _type      = ResultType.CREATE;
     _rules     = new Dictionary <string, Rule>();
     _reference = null;
 }
Пример #6
0
        private OntologyClass menuItemToClass(ToolStripMenuItem item)
        {
            TreeNode      selectedNode  = ((item.GetCurrentParent() as ContextMenuStrip).SourceControl as TreeView).SelectedNode;
            OntologyClass ontologyClass = selectedNode.Tag as OntologyClass;

            return(ontologyClass);
        }
Пример #7
0
        public ICollection <String> GetClassDataProperties(String classOntology)
        {
            ICollection <String> propertyList = new List <string>();
            OntologyClass        classMatch   = null;

            foreach (OntologyClass ontologyClasse in Ontology.AllClasses)
            {
                if (getSignificantWord(ontologyClasse.ToString(), '#').Equals(classOntology))
                {
                    classMatch = ontologyClasse;
                }
            }
            if (classMatch != null)
            {
                foreach (OntologyProperty classProperty in classMatch.IsDomainOf)
                {
                    foreach (OntologyProperty dataProperty in Ontology.OwlDatatypeProperties)
                    {
                        if (dataProperty.Equals(classProperty))
                        {
                            propertyList.Add(classProperty.ToString());
                        }
                    }
                }
                return(propertyList);
            }
            else
            {
                return(null);
            }
        }
Пример #8
0
 private void AddPropertiesFrom(OntologyClass ontologyClass, CompileUnitOption compileUnitOption)
 {
     foreach (var ontologyProperty in ontologyClass.IsDomainOf)
     {
         this.Members.AddRange(new PropertyWithBackingField(ontologyProperty));
     }
 }
Пример #9
0
 private void ProcessClass(OntologyClass ontologyClass, SchemaType parentType)
 {
     if (IncludeInOutput(ontologyClass))
     {
         var schemaType = new SchemaType();
         var resource   = ontologyClass.Resource as IUriNode;
         schemaType.Name    = MakeTypeName(resource);
         schemaType.TypeUri = resource.Uri;
         if (parentType == null)
         {
             // Needs to define an Id property
             schemaType.IdentifierProperty = new SchemaProperty
             {
                 Name         = _args.IdentifierPropertyName,
                 DeclaredType = typeof(string),
             };
         }
         else
         {
             schemaType.DerivedFrom = parentType;
         }
         foreach (var derivedClass in ontologyClass.DirectSubClasses)
         {
             ProcessClass(derivedClass, schemaType);
         }
     }
 }
Пример #10
0
        public static IEnumerable <OntologyProperty> IsExhaustiveDomainOfUniques(this OntologyClass oClass)
        {
            IEnumerable <OntologyProperty> allProperties       = oClass.IsExhaustiveDomainOf();
            IEnumerable <OntologyProperty> allUniqueProperties = allProperties.GroupBy(property => property.GetIri().ToString()).Select(group => group.First());

            return(allUniqueProperties);
        }
Пример #11
0
        public Result AddResult(OntologyClass ontologyClass, string name = null)
        {
            _saved = false;
            if (name == null)
            {
                name = Faton.FatonConstants.RESULT_NAME_NEW;
            }
            int defaultNamesCount = 0;

            foreach (Result r in Results)
            {
                if (r.Name.Contains(name))
                {
                    defaultNamesCount++;
                }
            }
            if (defaultNamesCount > 0)
            {
                name += string.Format("({0})", defaultNamesCount);
            }
            Result res = new Result(name, ResultType.CREATE, ontologyClass);

            Components.Add(res);

            return(res);
        }
Пример #12
0
        private void Nv_Drop(object sender, System.Windows.DragEventArgs e)
        {
            TabPage tabPage = schemesTabControl.SelectedTab;

            if (tabPage.Tag == null)
            {
                return;
            }
            network.NetworkView nv = tabPage.Controls.OfType <ElementHost>().First().Child as network.NetworkView;

            // Retrieve the client coordinates of the drop location.
            System.Windows.Point p           = new System.Windows.Point(MousePosition.X, MousePosition.Y);
            System.Windows.Point targetPoint = nv.PointFromScreen(p);

            // Retrieve the node that was dragged.
            if (!e.Data.GetDataPresent(typeof(DataContainer)))
            {
                return;
            }
            DataContainer ontologyClassContainer = (DataContainer)e.Data.GetData(typeof(DataContainer));

            OntologyClass ontologyClass = ontologyClassContainer.Data as OntologyClass;

            //Layout layout;

            Scheme scheme = (Scheme)schemesTabControl.SelectedTab.Tag;

            FactScheme.Argument arg = scheme.AddArgument(ontologyClass);

            network.Node node = nv.AddNode(Medium.Convert(arg), true);
        }
Пример #13
0
        /**
         * Retorna uma lista com as instancias da classe passada como parametro
         * */
        public ICollection <string> GetIndividualsbyClass(string str)
        {
            ICollection <String> listIndividual = new List <String>();


            // ontologyClass owlClass = ontology.CreateontologyClass(ontology.CreateUriNode("owl:"+str));
            OntologyClass owlClass = null;

            foreach (OntologyClass classe in Ontology.AllClasses)
            {
                if (classe.ToString().Contains(str))
                {
                    owlClass = classe;
                }
            }

            if (owlClass == null)
            {
                return(listIndividual);
            }

            foreach (OntologyResource individual in owlClass.Instances)
            {
                listIndividual.Add(individual.ToString());
            }
            return(listIndividual);
        }
Пример #14
0
        public ICollection <String> GetCorelatedObjectPropertiesByClass(String classOntology, String objectProperty)
        {
            bool          find      = false;
            List <String> listClass = new List <string>();

            foreach (OntologyProperty property in Ontology.OwlObjectProperties)
            {
                if (getSignificantWord(property.ToString(), '#').Equals(objectProperty))
                {
                    objectProperty = property.ToString();
                    find           = true;
                    break;
                }
            }

            if (find == false)
            {
                return(null);
            }

            OntologyClass classMatch = null;

            foreach (OntologyClass classComparer in Ontology.AllClasses)
            {
                if (getSignificantWord(classComparer.ToString(), '#').Equals(Ontology))
                {
                    classMatch = classComparer;
                    break;
                }
            }

            if (classMatch == null)
            {
                return(null);
            }

            foreach (OntologyResource individual in classMatch.Instances)
            {
                List <String> individualResults = this.RunQuery("SELECT ?resultado WHERE { <" + individual.ToString() + ">  <" + objectProperty + ">  ?resultado . }");
                if (individualResults != null)
                {
                    foreach (String individualResultString in individualResults)
                    {
                        List <String> classResults = (this.RunQuery("SELECT ?resultado WHERE { <" + getSignificantWord(individualResultString, '=').Trim() + ">  a  ?resultado . }"));
                        if (classResults != null)
                        {
                            foreach (String classResultString in classResults)
                            {
                                if (listClass.Contains(getSignificantWord(classResultString, '=').Trim()) == false && classResultString.Contains(Ontology.BaseUri.ToString()))
                                {
                                    listClass.Add(getSignificantWord(classResultString, '=').Trim());
                                }
                            }
                        }
                    }
                }
            }
            return(listClass);
        }
Пример #15
0
        internal InterfaceDeclaration(OntologyClass ontologyClass)
        {
            this.ontologyClass = ontologyClass;

            this.Initialize();
            this.AddSuperClasses();
            this.AddProperties();
        }
 public static bool IsXsdDatatype(this OntologyClass oClass)
 {
     if (oClass.IsNamed())
     {
         return(oClass.GetUri().AbsoluteUri.StartsWith(XmlSpecsHelper.NamespaceXmlSchema, StringComparison.Ordinal));
     }
     return(false);
 }
 public static IEnumerable <string> DtdlTypes(this OntologyClass oClass)
 {
     if (oClass.IsNamed())
     {
         return(oClass.GetUriNode().DtdlTypes());
     }
     return(new List <string>());
 }
        public static IEnumerable <OntologyClass> SuperClassesWithOwlThing(this OntologyClass cls)
        {
            IGraph        graph         = cls.Graph;
            IUriNode      owlThing      = graph.CreateUriNode(VocabularyHelper.OWL.Thing);
            OntologyClass owlThingClass = new OntologyClass(owlThing, graph);

            return(cls.SuperClasses.Append(owlThingClass));
        }
Пример #19
0
 public static bool IsXsdDatatype(this OntologyClass oClass)
 {
     if (oClass.IsNamed())
     {
         return oClass.GetIri().ToString().StartsWith(XmlSpecsHelper.NamespaceXmlSchema, StringComparison.Ordinal);
     }
     return false;
 }
 public static bool IsSimpleXsdWrapper(this OntologyClass oClass)
 {
     if (oClass.IsDatatype() && oClass.EquivalentClasses.Count() == 1)
     {
         return(oClass.EquivalentClasses.Single().IsXsdDatatype());
     }
     return(false);
 }
Пример #21
0
 public Relationship(OntologyProperty property, OntologyClass target)
 {
     if (!property.IsNamed() || !(target.IsNamed() || target.IsDatatype()))
     {
         throw new ArgumentException("Only named properties and named or datatype targets allowed.");
     }
     Property = property;
     Target   = target;
 }
Пример #22
0
        public static IEnumerable <OntologyProperty> IsScopedDomainOf(this OntologyClass cls)
        {
            OntologyGraph          graph         = cls.Graph as OntologyGraph;
            IUriNode               onProperty    = graph.CreateUriNode(new Uri("http://www.w3.org/2002/07/owl#onProperty"));
            IEnumerable <IUriNode> propertyNodes = cls.DirectSuperClasses.Where(superClass => superClass.IsRestriction())
                                                   .SelectMany(restriction => restriction.GetNodesViaProperty(onProperty)).UriNodes();

            return(propertyNodes.Select(node => graph.CreateOntologyProperty(node)));
        }
Пример #23
0
 public static IUriNode GetRestrictionProperty(this OntologyClass oClass)
 {
     if (!oClass.HasRestrictionProperty())
     {
         throw new RdfException($"Ontology class {oClass} does not have a restriction property.");
     }
     IUriNode onProperty = oClass.Graph.CreateUriNode(VocabularyHelper.OWL.onProperty);
     return oClass.GetNodesViaProperty(onProperty).UriNodes().First(node => node.IsOntologyProperty());
 }
        public Dictionary <string, List <SimilarClassPropertyDescription> > GetSimilarClassPropertiesMatrix(string classUri1, string classUri2, IProgress <double> progress = null)
        {
            OntologyClass classOfClasses1 = _o1.CreateOntologyClass(_o1.CreateUriNode("owl:Class"));
            OntologyClass classOfClasses2 = _o2.CreateOntologyClass(_o2.CreateUriNode("owl:Class"));

            var classProps_i = _o1.GetTriplesWithPredicateObject(_o1.CreateUriNode("rdfs:domain"), _o1.CreateUriNode(new Uri(classUri1))).ToList();
            var classProps_j = _o2.GetTriplesWithPredicateObject(_o2.CreateUriNode("rdfs:domain"), _o1.CreateUriNode(new Uri(classUri2))).ToList();

            //remove not owl: -Properties
            classProps_i.RemoveAll(t => !t.Subject.ToString().Contains("#"));
            classProps_j.RemoveAll(t => !t.Subject.ToString().Contains("#"));

            double[][] propsSimilarityMatrix = new double[classProps_i.Count][];
            for (int m = 0; m < classProps_i.Count; m++)
            {
                propsSimilarityMatrix[m] = new double[classProps_j.Count];
                string propName1 = (classProps_i[m] as Triple).Subject.ToString().Split('#')[1];
                for (int n = 0; n < classProps_j.Count; n++)
                {
                    string propName2 = (classProps_j[n] as Triple).Subject.ToString().Split('#')[1];
                    propsSimilarityMatrix[m][n] = GetWordNetSimilarityScore(propName1, propName2);

                    if (progress != null)
                    {
                        double progressValue = (m * classProps_j.Count + (n + 1)) / (double)(classProps_i.Count * classProps_j.Count);    //from 0 to 1
                        progress.Report(progressValue);
                    }
                }
            }

            Dictionary <string, List <SimilarClassPropertyDescription> > simDict = new Dictionary <string, List <SimilarClassPropertyDescription> >();

            for (int i = 0; i < propsSimilarityMatrix.Length; i++)
            {
                string key = classProps_i[i].Subject.ToString();
                if (!simDict.ContainsKey(key))
                {
                    simDict.Add(key, new List <SimilarClassPropertyDescription>());
                }

                for (int j = 0; j < propsSimilarityMatrix[i].Length; j++)
                {
                    simDict[key].Add(new SimilarClassPropertyDescription
                    {
                        ObjectName1       = classProps_i[i].Subject.ToString(),
                        ObjectName2       = classProps_j[j].Subject.ToString(),
                        SimObjectURI1     = classProps_i[i].GraphUri.ToString(),
                        SimObjectURI2     = classProps_j[j].GraphUri.ToString(),
                        SimilarityScore   = propsSimilarityMatrix[i][j],
                        MergePropRelation = MergePropertyRelation.EquivalentProperty
                    });
                }
            }

            return(simDict);
        }
Пример #25
0
 public static IEnumerable<OntologyProperty> IsExhaustiveDomainOf(this OntologyClass oClass)
 {
     IEnumerable<OntologyProperty> indirectScopedDomainProperties = oClass.SuperClasses.SelectMany(cls => cls.IsScopedDomainOf());
     IEnumerable<OntologyProperty> scopedDomainProperties = oClass.IsScopedDomainOf();
     IEnumerable<OntologyProperty> indirectDomainProperties = oClass.SuperClasses.SelectMany(cls => cls.IsDomainOf);
     IEnumerable<OntologyProperty> directDomainProperties = oClass.IsDomainOf;
     // The order is intentional -- the restrictions come before rdfs:domains, and more generic ones go first
     IEnumerable<OntologyProperty> allDomainProperties = indirectScopedDomainProperties.Union(scopedDomainProperties).Union(indirectDomainProperties).Union(directDomainProperties);
     return allDomainProperties.Distinct(new OntologyResourceComparer()).Select(ontResource => ontResource as OntologyProperty);
 }
Пример #26
0
        protected void CreateNew(string id)
        {
            IUriNode      newUri = GraphProxy.Graph.CreateUriNode(new Uri(id));
            INode         type   = GraphProxy.Graph.CreateUriNode(new Uri(OntologyHelper.PropertyType));
            INode         namedInvididualClass = GraphProxy.Graph.CreateUriNode(new Uri(NamedIndividual));
            OntologyClass ontologyClass        = GetClass(EntityName);

            GraphProxy.Graph.Assert(new Triple(newUri, type, ontologyClass.Resource, GraphProxy.Graph));
            GraphProxy.Graph.Assert(new Triple(newUri, type, namedInvididualClass, GraphProxy.Graph));
        }
Пример #27
0
        public Argument AddArgument(OntologyClass klass)
        {
            _saved = false;
            Argument arg = new Argument(klass, klass.Name);

            arg.Order = ++_numArgs;
            Components.Add(arg);

            return(arg);
        }
Пример #28
0
        public Argument(OntologyClass klass, string name = null, bool inherit = true) : this()
        {
            ArgType = ArgumentType.IOBJECT;
            _klass  = klass;

            _attrs = klass.AllAttributes;
            foreach (var attr in _attrs)
            {
                Conditions.Add(attr, new List <ArgumentCondition>());
            }
        }
        public ListViewOntologyInfoEntry(String localName, String fullName, String modelNamespace, OntologyClass oClass)
        {   // create a basic instance we can use.
            this.Name      = localName;
            this.FullName  = fullName;
            this.NameSpace = modelNamespace;
            this.OClass    = oClass;

            this.SubItems = new List <ListViewOntologyInfoEntry>();

            // create the subItemsDictionary...
            this.subItemsDictionary = new Dictionary <string, ListViewOntologyInfoEntry>();
        }
        public static int Depth(this OntologyClass oClass)
        {
            int largestParentDepth = 0;

            foreach (OntologyClass superClass in oClass.DirectSuperClasses)
            {
                int superClassDepth = superClass.Depth();
                if (superClassDepth > largestParentDepth)
                {
                    largestParentDepth = superClassDepth;
                }
            }
            return(largestParentDepth + 1);
        }