private void MainExtractFacts(OwlClass owlClass, string text) { if (factsExtracted) { return; } string owlClassName = OntologyForm.ConvertNameNode(owlClass); foreach (OwlEdge owlEdge in owlClass.ParentEdges) { OwlIndividual owlIndividual = (OwlIndividual)(owlEdge.ParentNode); string owlIndividualName = OntologyForm.ConvertNameNode(owlIndividual); TreeNode nodeIndividual = new TreeNode(owlIndividualName); try { ExtractFactsFromIndividual(owlIndividual, nodeIndividual, text); nodes.Add(nodeIndividual); } catch (Exception exception) { nodes.Add(new TreeNode(owlIndividualName + ": " + exception.Message)); } } factsExtracted = true; }
public static IOwlRelation Create(OwlClass parent, OwlClass child) { return(new OwlRelation { Parent = parent, Child = child }); }
private void WriteTree(OwlClass owlClass, TreeNode treeNode) { foreach (OwlEdge owlEdge in owlClass.ParentEdges) { OwlNode owlNode = (OwlNode)owlEdge.ParentNode; if (owlNode is OwlClass) { TreeNode childTreeNode = new TreeNode(ConvertNameNode(owlNode)); WriteTree((OwlClass)owlNode, childTreeNode); treeNode.Nodes.Add(childTreeNode); } } }
public void test5(string file) { IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); string baseUri = "http://www.owl-ontologies.com/travel.owl#"; OwlClass hotelNode = (OwlClass)graph.Nodes["http://www.owl-ontologies.com/travel.owl#LuxuryHotel"]; OwlIndividual newHotel = new OwlIndividual(baseUri + "PellensPalace", hotelNode); graph.Nodes.Add(newHotel); IOwlGenerator generator = new OwlXmlGenerator(); generator.GenerateOwl(graph, @"c:\travelnew.owl"); }
public void test8() { OwlGraph ontology = new OwlGraph(); ontology.NameSpaces["xmlns:" + OwlNamespaceCollection.OwlNamespacePrefix] = OwlNamespaceCollection.OwlNamespace; ontology.NameSpaces["xmlns:" + OwlNamespaceCollection.RdfSchemaNamespacePrefix] = OwlNamespaceCollection.RdfSchemaNamespace; ontology.NameSpaces["xmlns:daml"] = "http://www.daml.org/2001/03/daml+oil#"; ontology.NameSpaces["xmlns:dc"] = "http://purl.org/dc/elements/1.1/"; ontology.NameSpaces["xmlns"] = "http://www.owl-ontologies.com/test.owl#"; ontology.NameSpaces["xml:base"] = "http://www.owl-ontologies.com/test.owl"; string baseUri = "http://www.owl-ontologies.com/test.owl#"; OwlClass testCls = new OwlClass(baseUri + "TestClass"); ontology.Nodes.Add(testCls); OwlRestriction testRestriction = new OwlRestriction("blankID:1"); ontology.Nodes.Add(testRestriction); OwlObjectProperty testProp = new OwlObjectProperty(baseUri + "testProp"); ontology.Nodes.Add(testProp); OwlEdge subClassOfRelation = new OwlEdge(OwlNamespaceCollection.RdfSchemaNamespace + "subClassOf"); subClassOfRelation.AttachParentNode(testCls); subClassOfRelation.AttachChildNode(testRestriction); ontology.Edges.Add(subClassOfRelation); OwlEdge onPropertyRelation = new OwlEdge(OwlNamespaceCollection.OwlNamespace + "onProperty"); onPropertyRelation.AttachParentNode(testRestriction); onPropertyRelation.AttachChildNode(testProp); ontology.Edges.Add(onPropertyRelation); OwlLiteral val = new OwlLiteral("1", null, "http://www.w3.org/2001/XMLSchema#int"); OwlEdge cardinalityRelation = new OwlEdge(OwlNamespaceCollection.OwlNamespace + "cardinality"); cardinalityRelation.AttachParentNode(testRestriction); cardinalityRelation.AttachChildNode(val); ontology.Edges.Add(cardinalityRelation); IOwlGenerator generator = new OwlXmlGenerator(); generator.GenerateOwl(ontology, @"c:\test.owl"); }
public void test2() { OwlGraph ontology = new OwlGraph(); ontology.NameSpaces["xmlns:" + OwlNamespaceCollection.OwlNamespacePrefix] = OwlNamespaceCollection.OwlNamespace; ontology.NameSpaces["xmlns:" + OwlNamespaceCollection.RdfSchemaNamespacePrefix] = OwlNamespaceCollection.RdfSchemaNamespace; ontology.NameSpaces["xmlns:daml"] = "http://www.daml.org/2001/03/daml+oil#"; ontology.NameSpaces["xmlns:domain"] = "http://www.owl-ontologies.com/domain.owl#"; ontology.NameSpaces["xmlns:dc"] = "http://purl.org/dc/elements/1.1/"; ontology.NameSpaces["xmlns"] = "http://www.owl-ontologies.com/test.owl#"; ontology.NameSpaces["xml:base"] = "http://www.owl-ontologies.com/test.owl"; string baseUri = "http://www.owl-ontologies.com/test.owl#"; string altUri = "http://www.owl-ontologies.com/domain.owl#"; OwlOntology o = new OwlOntology(baseUri + "testOntology"); ontology.Nodes.Add(o); OwlClass a = new OwlClass(altUri + "ClassA"); //ontology.Nodes.Add(a); OwlIndividual inst = new OwlIndividual(baseUri + "Car", a); ontology.Nodes.Add(inst); //OwlClass b = new OwlClass(baseUri + "ClassB"); //ontology.Nodes.Add(b); // OwlClass concept = new OwlClass(altUri+node.Type); //Create a concept node // // OwlIndividual instance = new OwlIndividual(baseUri + node.ID, concept); // create an instance node as individual of concept node // _description.Nodes.Add(instance); //OwlEdge relation = new OwlEdge(OwlNamespaceCollection.RdfSchemaNamespace + "subClassOf"); //relation.AttachParentNode(a); //relation.AttachChildNode(b); //ontology.Edges.Add(relation); IOwlGenerator generator = new OwlXmlGenerator(); generator.GenerateOwl(ontology, @"c:\example2.owl"); }
public void test4(string file) { IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); Console.WriteLine("Retrieving some specific data:"); // Here we will retrieve the enumerator in order to get all the nodes from the file IDictionaryEnumerator nEnumerator = (IDictionaryEnumerator)graph.Nodes.GetEnumerator(); while (nEnumerator.MoveNext()) { // Get the node from the graph OwlNode node = (OwlNode)graph.Nodes[(nEnumerator.Key).ToString()]; // We will cast the node to a OwlClass because we are looking for classes OwlClass clsNode = node as OwlClass; // If clsNode is different from null, then we are dealing with an OwlClass -> OK // If the clsNode is not anonymous, means that we have a class with a proper name -> OK if ((clsNode != null) && (!clsNode.IsAnonymous())) { // So, now we have a good owl-class, we will look for any subClassOf relations (edges) IOwlEdgeList subclassEdges = (IOwlEdgeList)node.ChildEdges["http://www.w3.org/2000/01/rdf-schema#subClassOf"]; if (subclassEdges != null) { // We will list all the edges and check if the target of the edge is the class we want to // have as the superclass foreach (OwlEdge s in subclassEdges) { if (s.ChildNode.ID == "http://www.owl-ontologies.com/travel.owl#Accommodation") { Console.WriteLine(node.ID); } } } } } }
private void btnCalcCountKeyWords_Click(object sender, EventArgs e) { List <string> keyWords = new List <string>(); OwlClass owlMainClass = (OwlClass)((OwlItem)cbHeadOwlClass.SelectedItem).owlNode; foreach (OwlEdge owlEdge in owlMainClass.ParentEdges) { OwlIndividual owlIndividual = (OwlIndividual)owlEdge.ParentNode; foreach (OwlEdge owlAttribute in owlIndividual.ChildEdges) { if (OntologyForm.ConvertNameNode(owlAttribute) == "HasKeyWord") { OwlNode attribute = (OwlNode)(owlAttribute.ChildNode); keyWords.Add(attribute.ID); } } } foreach (ListViewItem lvi in lvReviews.SelectedItems) { Review review = (Review)lvi.Tag; review.CalcCountKeyWords(keyWords); lvi.SubItems[3].Text = review.CountKeyWords.ToString(); } }
public void ExtractFacts(OwlClass owlClass, bool toLower, List <string> stopWords) { string thisText = this.text.Replace("\r\n", "; "); string text = ""; char[] punctuation = { '!', ',', '.', '?', ';', ' ' }; for (int i = 0; i < thisText.Length; i++) { if (Char.IsLetterOrDigit(thisText[i]) || punctuation.Contains(thisText[i])) { text += thisText[i]; } } text = toLower ? text.ToLower() : text; foreach (string word in stopWords) { text = text.Replace(word.ToLower(), " "); } while (text.Contains(" ")) { text = text.Replace(" ", " "); } MainExtractFacts(owlClass, text); }
public void test1(string file) { IOwlParser parser = new OwlXmlParser(); IOwlGraph graph = parser.ParseOwl(file); ArrayList errors = ((OwlParser)parser).Errors; ArrayList warnings = ((OwlParser)parser).Warnings; ArrayList messages = ((OwlParser)parser).Messages; //FileStream info = new FileStream("c:/info.txt", FileMode.OpenOrCreate); //StreamWriter sw = new StreamWriter(info); //sw.AutoFlush = true; //IOwlGenerator generator = new OwlXmlGenerator(); //generator.GenerateOwl(graph, @"c:\example1.owl"); //info = new FileStream("C:/generated.txt", FileMode.OpenOrCreate); //sw = new StreamWriter(info); //sw.AutoFlush = true; // foreach(string msg in messages) // { // sw.WriteLine(msg); // } // // Console.WriteLine("Graph parsed successfully with {0} errors and {1} warnings\n\n",errors.Count,warnings.Count); // // foreach(string err in errors) // { // Console.WriteLine("Error: "+err); // } // // foreach(string war in warnings) // { // Console.WriteLine("Warning: "+war); // } // // Console.WriteLine("The graph contains {0} node(s) and {1} edge(s).", graph.Nodes.Count, graph.Edges.Count); string baseuri = graph.NameSpaces["xmlns"]; Console.WriteLine("The basuri is " + baseuri); OwlClass owlAnnotation = new OwlClass(baseuri + "Annotation"); //Create a parent (Annotation) node to relate to OwlGraph newGraph = new OwlGraph(); newGraph.NameSpaces["xmlns:" + OwlNamespaceCollection.OwlNamespacePrefix] = OwlNamespaceCollection.OwlNamespace; newGraph.NameSpaces["xmlns:" + OwlNamespaceCollection.RdfSchemaNamespacePrefix] = OwlNamespaceCollection.RdfSchemaNamespace; newGraph.NameSpaces["xmlns:daml"] = "http://www.daml.org/2001/03/daml+oil#"; newGraph.NameSpaces["xmlns:domain"] = "http://www.owl-ontologies.com/domain.owl#"; newGraph.NameSpaces["xmlns:dc"] = "http://purl.org/dc/elements/1.1/"; newGraph.NameSpaces["xmlns"] = "http://www.owl-ontologies.com/test.owl#"; newGraph.NameSpaces["xml:base"] = "http://www.owl-ontologies.com/test.owl"; newGraph.NameSpaces["xmlns:meta"] = baseuri; string newUri = "http://www.owl-ontologies.com/test.owl#"; OwlIndividual pp = new OwlIndividual(newUri + "Test", owlAnnotation); //Create the annotation newGraph.Nodes.Add(pp); IOwlGenerator generator = new OwlXmlGenerator(); generator.GenerateOwl(newGraph, @"c:\example2.owl"); }
public void ExtractFacts(OwlClass owlClass, bool toLower) { string thisText = this.text.Replace("\r\n", "; "); MainExtractFacts(owlClass, toLower ? thisText.ToLower() : thisText); }