Dictionary <string, List <string> > GetNonVisualFeatures(IOwlLiteral literal) { Dictionary <string, List <string> > result = new Dictionary <string, List <string> >(); OwlNode nodeClass = (OwlNode)literal.ParentEdges[0].ParentNode; foreach (IOwlEdge edge in nodeClass.ChildEdges) { string edgeMap = edge.ID; if (annotations.ContainsKey(edgeMap)) { string featureName = edgeMap.Substring(eAnnotation.Length); if (featureName[0] == '_') { featureName = featureName.Substring(1); if (!result.ContainsKey(featureName)) { result.Add(featureName, new List <string>()); } List <string> featuresValue = result[featureName]; string[] values = edge.ChildNode.ID.Split('\n'); featuresValue.AddRange(values); } } } return(result); }
public MindMapOntology(string fileName) { Concepts = new Dictionary <string, MindMapConcept>(); IOwlGraph graph; IOwlParser parser = new OwlXmlParser(); object o = parser.ParseOwl(fileName); graph = (IOwlGraph)o; foreach (DictionaryEntry entry in graph.Nodes) { IOwlNode node = (IOwlNode)entry.Value; if (node.GetType() == typeof(OwlAnnotationProperty) && node.ID != eMaplex && node.ID != eDefinition) { annotations.Add(node.ID, ((string)entry.Key).Substring(eAnnotation.Length)); } } foreach (DictionaryEntry entry in graph.Literals) { IOwlLiteral literal = (IOwlLiteral)entry.Value; if (literal.ParentEdges[0].ParentNode.ChildEdges[eLabel, 0] == null || ((IOwlLiteral)(literal.ParentEdges[0].ParentNode.ChildEdges[eLabel, 0].ChildNode)) != literal) { continue; } MindMapConcept concept = new MindMapConcept(); concept.Name = literal.ID; concept.Defintion = GetDefinition(literal); concept.VisualProperties = GetVisualFeatures(literal); concept.NonVisualProperties = GetNonVisualFeatures(literal); concept.Maplex = GetMaplex(literal); if (concept.Name.ToUpper() != "THING" && GetParent(literal) != null) { concept.ParentConceptName = GetParent(literal).ID; } else { concept.ParentConceptName = ""; } Concepts.Add(concept.Name, concept); //Concepts.Add(concept.Name.Split('^')[0], concept); } foreach (KeyValuePair <string, MindMapConcept> concept in Concepts) { if (concept.Value.Name.ToUpper() != "THING" && concept.Value.ParentConceptName != null && concept.Value.ParentConceptName != "") { try { concept.Value.Parent = Concepts[concept.Value.ParentConceptName]; } catch (Exception) { concept.Value.Parent = null; } } else { concept.Value.Parent = null; } } }
List <MyWordInfo> GetMaplex(IOwlLiteral conceptLiteral) { try { OwlNode nodeClass = (OwlNode)conceptLiteral.ParentEdges[0].ParentNode; string Maplex = nodeClass.ChildEdges[eMaplex, 0].ChildNode.ID.Split('^')[0]; string[] allMaplexes = Maplex.Split('\n'); List <MyWordInfo> result = new List <MyWordInfo>(); for (int i = 0; i < allMaplexes.Length; i++) { MyWordInfo word = new MyWordInfo(); string[] parts = allMaplexes[i].Split('-'); word.Word = parts[0]; //TODO: handle the adjective and adverb switch (parts[1][0]) { case 'n': case 'N': word.Pos = PartsOfSpeech.Noun; break; case 'v': case 'V': word.Pos = PartsOfSpeech.Verb; break; case 'a': case 'A': if (parts[1][2] == 'j' || parts[1][2] == 'J') { word.Pos = PartsOfSpeech.Adj; } else { word.Pos = PartsOfSpeech.Adv; } break; default: word.Pos = PartsOfSpeech.Unknown; break; } int index = 1; for (; parts[1][index] < '0' || parts[1][index] > '9'; index++) { ; } string senseNumber = parts[1].Substring(index); word.Sense = int.Parse(senseNumber); result.Add(word); } return(result); } catch (Exception) { return(new List <MyWordInfo>()); } }
/// <summary> /// Merges the srcGraph into this graph object /// </summary> /// <param name="srcGraph">An object that implements the IOwlGraph interace</param> /// <param name="skipDuplicateEdges">A flag that indicates whether duplicate edges present in both graphs should be skipped during the merge process.</param> public void Merge(IOwlGraph srcGraph, bool skipDuplicateEdges) { if (srcGraph == null) { return; } Hashtable literalsAdded = new Hashtable(); //go through all the nodes in the source graph IDictionaryEnumerator enumerator = (IDictionaryEnumerator)srcGraph.Nodes.GetEnumerator(); while (enumerator.MoveNext()) { //Console.WriteLine(((IOwlNode)(enumerator.Value)).ID); //add this node to the graph IOwlNode srcParentNode = (IOwlNode)enumerator.Value; IOwlNode destParentNode = AddNode(srcParentNode.ID); //go through all of the src node's child edges foreach (IOwlEdge srcChildEdge in srcParentNode.ChildEdges) { //for each of the src node's child edges do... IOwlNode destChildNode; if (srcChildEdge.ChildNode is IOwlLiteral) { IOwlLiteral srcChildLiteral = srcChildEdge.ChildNode as IOwlLiteral; literalsAdded[srcChildLiteral] = srcChildLiteral; destChildNode = AddLiteral(srcChildLiteral.Value, srcChildLiteral.LangID, srcChildLiteral.Datatype); } else { destChildNode = AddNode(srcChildEdge.ChildNode.ID); } //Now we have the parent and the child nodes added to the graph.. bool edgeExists = false; if (skipDuplicateEdges) { //does the new parent node and the new child node have an edge with the same ID as srcChildEdge? //go through all the child edges of destParentNode foreach (OwlEdge tempEdge in destParentNode.ChildEdges) { if ((tempEdge.ChildNode == destChildNode) && (tempEdge.ID == srcChildEdge.ID)) { edgeExists = true; break; } } } if (!skipDuplicateEdges || (skipDuplicateEdges && !edgeExists)) { OwlEdge destChildEdge = new OwlEdge(srcChildEdge.ID); destParentNode.AttachChildEdge(destChildEdge); destChildEdge.AttachChildNode(destChildNode); //add the edge to the graph AddEdge(destChildEdge); } } } }
string GetDefinition(IOwlLiteral conceptLiteral) { try { OwlNode nodeClass = (OwlNode)conceptLiteral.ParentEdges[0].ParentNode; return(nodeClass.ChildEdges[eDefinition, 0].ChildNode.ID.Split('^')[0]); } catch (Exception) { return(""); } }
OwlLiteral GetParent(IOwlLiteral conceptLiteral) { try { OwlNode nodeClass = (OwlNode)conceptLiteral.ParentEdges[0].ParentNode; OwlNode parentClass = (OwlNode)nodeClass.ChildEdges[eSubClass, 0].ChildNode; return((OwlLiteral)parentClass.ChildEdges[eLabel, 0].ChildNode); } catch (Exception) { return(null); } }
List <OwlLiteral> GetChildren(IOwlLiteral conceptLiteral) { try { List <OwlLiteral> result = new List <OwlLiteral>(); OwlNode nodeClass = (OwlNode)conceptLiteral.ParentEdges[0].ParentNode; IOwlEdgeCollection edges = nodeClass.ParentEdges; foreach (IOwlEdge edge in edges) { OwlNode childClass = (OwlNode)edge.ParentNode; result.Add((OwlLiteral)childClass.ChildEdges[eLabel, 0].ChildNode); } return(result); } catch (Exception) { return(new List <OwlLiteral>()); } }
/// <summary> /// Adds a literal to the graph /// </summary> /// <param name="literal">The new literal to add.</param> /// <exception cref="ArgumentException">A literal with the same value, datatype URI and language ID alreday exists in the graph.</exception> public void AddLiteral(IOwlLiteral literal) { _literals.Add((OwlLiteral)literal); }
/// <summary> /// Adds a literal to the graph /// </summary> /// <param name="literal">The new literal to add.</param> /// <exception cref="ArgumentException">A literal with the same value, datatype URI and language ID alreday exists in the graph.</exception> public void AddLiteral(IOwlLiteral literal) { _literals.Add((OwlLiteral)literal); }