public override void BuildRelationship(Shape shape)
        {
            Shape incomingShape = ToolKit.QueryFlowRelationship(shape, VisGluedShapesFlags.visGluedShapesIncoming2D)[0];

            Shape outgoingShape = ToolKit.QueryFlowRelationship(shape, VisGluedShapesFlags.visGluedShapesOutgoing2D)[0];

            Shape[] incomingShapes = ToolKit.ShapeToArray(incomingShape);
            Shape[] outgoingShapes = ToolKit.ShapeToArray(outgoingShape);

            foreach (Shape incoming in incomingShapes)
            {
                foreach (Shape outgoing in outgoingShapes)
                {

                    IOwlNode incomingNode = base._graph.Nodes[ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, ToolKit.StringShift(incoming.Text))];
                    IOwlNode outgoingNode = base._graph.Nodes[ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, ToolKit.StringShift(outgoing.Text))];

                    string relationship = ToolKit.FlowElementNaming(incoming, shape, outgoing);
                    IOwlNode relationshipNode = new OwlNode(ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, relationship));
                    IOwlEdge incomingEdge = new OwlEdge(ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, "incoming"));
                    IOwlEdge outgoingEdge = new OwlEdge(ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, "outgoing"));
                    incomingEdge.ChildNode = new OwlLiteral(relationship,"en-us","xsd:string");
                    incomingNode.AttachChildEdge(incomingEdge);

                    outgoingEdge.ChildNode = new OwlLiteral(relationship, "en-us", "xsd:string");
                    outgoingNode.AttachChildEdge(outgoingEdge);

                }
            }
        }
Esempio n. 2
0
        /// <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);
                    }
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the OwlClass class with the given Uri and TypeNode
 /// </summary>
 /// <param name="nodeUri">A string representing the Uri of this Resource</param>
 /// <param name="typeNode">The OwlNode object to attach to the edge specifying the type. This is usually a node with ID owl:Class.</param>
 /// <exception cref="ArgumentNullException">typeNode is a null reference</exception>
 public OwlClass(string nodeUri, OwlNode typeNode)
 {
     if(typeNode == null)
         throw(new ArgumentNullException());
     ID = nodeUri;
     _typeEdge = new OwlEdge(OwlNamespaceCollection.RdfNamespace+"type");
     _typeEdge.AttachChildNode(typeNode);
     AttachChildEdge(_typeEdge);
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the OwlRestriction class with the given Uri and TypeNode
 /// </summary>
 /// <param name="nodeUri">A string representing the Uri of this Resource</param>
 /// <param name="typeNode">The OwlNode object to attach to the edge specifying the type. This is usually a node with ID owl:Restriction.</param>
 /// <exception cref="ArgumentNullException">typeNode is a null reference</exception>
 public OwlRestriction(string nodeUri, OwlNode typeNode)
 {
     if (typeNode == null)
     {
         throw(new ArgumentNullException());
     }
     ID        = nodeUri;
     _typeEdge = new OwlEdge(OwlNamespaceCollection.RdfNamespace + "type");
     _typeEdge.AttachChildNode(typeNode);
     AttachChildEdge(_typeEdge);
 }
        protected IOwlIndividual BuildProperty(Shape shape, IOwlIndividual individual)
        {
            IOwlEdge idEdge = new OwlEdge(ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, "id"));
            idEdge.ChildNode = new OwlLiteral(shape.ID.ToString(), "en-us", "http://www.w3.org/2001/XMLSchema#string");

            individual.AttachChildEdge(idEdge);

            IOwlEdge nameEdge = new OwlEdge(ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, "name"));
            nameEdge.ChildNode = new OwlLiteral(shape.Name.ToString(), "en-us", "http://www.w3.org/2001/XMLSchema#string");

            individual.AttachChildEdge(nameEdge);

            return individual;
        }
        /// <summary>
        /// Processes an edge in the XML document. 
        /// </summary>
        /// <param name="node">The XmlNode to process.</param>
        /// <param name="parent">The parent of the current node.</param>
        /// <returns>Returns a reference to the new edge created</returns>
        private Object ProcessEdge(XmlNode node,  Object parent)
        {
            //if the node is a comment or anything else then totally ignore
            if((node.NodeType == XmlNodeType.Comment) || (node.NodeType == XmlNodeType.None) || (node.NodeType == XmlNodeType.Whitespace) || (node.NodeType == XmlNodeType.SignificantWhitespace))
                return true;
            OwlEdge rEdge = null;

            if(node.NodeType == XmlNodeType.Element)
            {
                //get the xml:base attribute...
                XmlAttribute xmlBaseAttr = node.Attributes["xml:base"];
                if((xmlBaseAttr == null) && (parent != null))
                {
                    //ok the child does not have an xml:base... and the parent is not null i.e. this node is not a child of the rdf:RDF root
                    xmlBaseAttr = node.ParentNode.Attributes["xml:base"];
                    if(xmlBaseAttr != null)
                        node.Attributes.Append(xmlBaseAttr);
                }
            }

            rEdge = new OwlEdge();

            OwlNode parentOwlNode = (OwlNode)parent;
            //process the xml:lang attribute if applicable
            //rEdge.LangID = parentOwlNode.LangID;

            if(ParseEdgeRdfAttributes(node,rEdge)) //if the process attributes method returns true then process the children of this node
            {
                if(node.HasChildNodes)
                {
                    int count = node.ChildNodes.Count;
                    for(int i=0;i<count;i++)
                        ProcessNode(node.ChildNodes[i], rEdge);
                }
            }

            if(!ParseEdgeSyntax(node,rEdge, parentOwlNode))
            {
                rEdge.ID = node.NamespaceURI+node.LocalName;
                rEdge.AttachParentNode(parentOwlNode);

            }

            //coming back up the tree
            ParseEdgeAttributes(node,rEdge);

            //if the edge is dangling then put an empty Literal on it.
            if(rEdge.ChildNode == null)
                rEdge.AttachChildNode(_owlGraph.AddLiteral("",null,null));

            //add the edge to the Graph
            _owlGraph.AddEdge(rEdge);

            return rEdge;
        }
        /// <summary>
        /// Parses the rdf:value, rdf:type attributes as well as any attributes not part of the OWL, RDF or XML namespace
        /// </summary>
        /// <param name="node">The XmlNode on which the attributes appear</param>
        /// <param name="rNode">The OwlNode to which the attributes must be applied</param>
        private void ParseNodeAttributes(XmlNode node, OwlNode rNode)
        {
            int count = node.Attributes.Count;
            for(int i=0;i<count;i++)
            {
                XmlAttribute attr = node.Attributes[i];
                if(!IsOwlRdfXmlProperty(attr) || (attr.Name=="rdf:type") || (attr.Name == "rdf:value"))
                {
                    if(IsUnqualifiedRdfProperty(node.Attributes[i]))
                        OnWarning("Unqualified use of rdf:"+node.Attributes[i].LocalName);

                    //create a new edge
                    string edgeUri = PrependXmlBase(attr.NamespaceURI+attr.LocalName, GetXmlBase(node));
                    OwlEdge rEdge = new OwlEdge(edgeUri);
                    OwlNode childNode = null;
                    if(attr.Name == "rdf:type")
                    {
                        childNode = (OwlNode)_owlGraph.AddNode(PrependXmlBase(attr.Value,GetXmlBase(node)));
                    }
                    else
                    {
                        childNode = (OwlLiteral)_owlGraph.AddLiteral(attr.Value,rNode.LangID,GetDatatypeUri(node));
                    }

                    rNode.AttachChildEdge(rEdge);
                    rEdge.AttachChildNode(childNode);
                    //add the new edge to the graph
                    _owlGraph.AddEdge(rEdge);
                }
            }
        }
        /// <summary>
        /// Parses the OWL syntax on an edge.
        /// </summary>
        /// <param name="node">The XML Node representing the OWL edge</param>
        /// <param name="rEdge">The edge</param>
        /// <param name="parentNode">The parent OWL node</param>
        /// <returns>True if the edge was given an ID and attached to the parent node</returns>
        private bool ParseEdgeSyntax(XmlNode node, OwlEdge rEdge, OwlNode parentNode)
        {
            //first get the NameSpace URI, NameSpace prefix and the LocalName for the node
            String nameSpaceURI = node.NamespaceURI;
            String nameSpacePrefix = node.Prefix;
            String localName = node.LocalName;
            if(IsNonSyntacticElement(node))
            {
                rEdge.ID = nameSpaceURI + localName;

                if(rEdge.ID == (OwlNamespaceCollection.RdfNamespace + "type"))
                {
                    OwlNode typeNode;
                    if(rEdge.ChildNode.ID == (OwlNamespaceCollection.OwlNamespace + "DatatypeProperty"))
                    {
                        typeNode = (OwlNode)_owlGraph.AddNode(OwlNamespaceCollection.OwlNamespace+"DatatypeProperty");
                        OwlDatatypeProperty newNode = new OwlDatatypeProperty(parentNode.ID,typeNode);
                        _owlGraph.AddEdge(newNode.Type);
                        MoveEdges(parentNode, newNode);
                        _owlGraph.Nodes.Remove(parentNode);
                        _owlGraph.AddNode(newNode);
                        rEdge.AttachParentNode(newNode);
                        return true;
                    }
                    if(rEdge.ChildNode.ID == (OwlNamespaceCollection.OwlNamespace + "ObjectProperty"))
                    {
                        typeNode = (OwlNode)_owlGraph.AddNode(OwlNamespaceCollection.OwlNamespace+"ObjectProperty");
                        OwlObjectProperty newNode = new OwlObjectProperty(parentNode.ID,typeNode);
                        _owlGraph.AddEdge(newNode.Type);
                        MoveEdges(parentNode, newNode);
                        _owlGraph.Nodes.Remove(parentNode);
                        _owlGraph.AddNode(newNode);
                        rEdge.AttachParentNode(newNode);
                        return true;
                    }

                }

                rEdge.AttachParentNode(parentNode);
                return true;
            }

            if(IsSyntacticElement(node))
            {
                OnError("Cannot use " + node.Name + " as a property element");
                return false;
            }

            // It is an instance of a property
            rEdge.ID = nameSpaceURI + localName;
            rEdge.AttachParentNode(parentNode);
            return true;

            //			OnWarning("Unknown property element "+ node.Name);
            //			return false;
        }
 /// <summary>
 /// Parses the OWL Attributes rdf:resource, rdf:nodeID, rdf:parseType, and xml:lang as they appear on an edge
 /// </summary>
 /// <param name="node">The XmlNode on which the attributes appear</param>
 /// <param name="rEdge">The OwlEdge to which the attributes must be applied</param>
 /// <returns>True if the children of the specified XML Node should be parsed</returns>
 private bool ParseEdgeRdfAttributes(XmlNode node, OwlEdge rEdge)
 {
     int attrFound = 0;
     bool parseChildren = true;
     XmlNode attr = node.Attributes["rdf:resource"];
     if(attr != null)
     {
         ProcessRdfResource(node, rEdge, attr.Value);
         attrFound = 1;
         parseChildren = false;
     }
     attr = node.Attributes["rdf:nodeID"];
     if(attr != null)
     {
         ProcessRdfNodeID(rEdge, attr.Value);
         attrFound += 2;
         parseChildren = false;
     }
     attr = node.Attributes["rdf:parseType"];
     if(attr != null)
     {
         ProcessRdfParseType(node,rEdge,attr.Value);
         attrFound += 4;
         parseChildren = false;
     }
     attr = node.Attributes["xml:lang"];
     if(attr != null)
     {
         rEdge.LangID = attr.Value;
     }
     switch(attrFound)
     {
         case 3:
             OnError("Cannot use rdf:resource and rdf:nodeID together");
             break;
         case 5:
             OnError("Cannot use rdf:resource and rdf:parseType together");
             break;
         case 6:
             OnError("Cannot use rdf:nodeID and rdf:parseType together");
             break;
         case 7:
             OnError("Cannot use rdf:resource, rdf:nodeID and rdf:parseType together");
             break;
     }
     return parseChildren;
 }
        /// <summary>
        /// Process the rdf:value and any attributes not in the rdf or xml namespace
        /// </summary>
        /// <param name="node">The XmlNode that attributes appear on</param>
        /// <param name="rEdge">The Owl edge that the attributes must be applied to.</param>
        private void ParseEdgeAttributes(XmlNode node, OwlEdge rEdge)
        {
            //go through all the attributes
            int count = node.Attributes.Count;
            for(int i=0;i<count;i++)
            {
                XmlAttribute attr = node.Attributes[i];

                if((!IsSyntacticElement(attr))  || (attr.Prefix == "rdf" && attr.LocalName == "value"))
                {
                    if((attr.NamespaceURI == null) || (attr.NamespaceURI.Length == 0))
                    {
                        OnError("Unqualified attribute: "+attr.LocalName);
                        continue;
                    }
                    if((attr.Name == "rdf:value")&& (rEdge.ChildNode is OwlLiteral))
                    {
                        OnError("Cannot use rdf:value ("+attr.Value+") as property for a literal ("+((OwlLiteral)rEdge.ChildNode).Value+").");
                        continue;
                    }
                    //if the childnode of the edge is a literal then it cant have any arcs going out from it
                    if((rEdge.ChildNode != null) && (rEdge.ChildNode is OwlLiteral) && (attr.Name != "rdf:datatype"))
                    {
                        OnError("Cannot have property "+attr.Name+" for an Owl Literal "+rEdge.ChildNode.ID);
                        continue;
                    }

                    string edgeID = attr.NamespaceURI+attr.LocalName;
                    string literalValue = attr.Value;
                    string langID = rEdge.LangID;
                    string datatypeUri = GetDatatypeUri(node);

                    //if this edge does not have a child node then create a blank node and add it
                    if(rEdge.ChildNode == null)
                        rEdge.AttachChildNode((OwlNode)_owlGraph.AddNode(GetBlankNodeUri(null)));

                    //make an edge from the child of rEdge
                    OwlEdge childEdge = new OwlEdge();
                    childEdge.ID = edgeID;
                    OwlLiteral childLiteral = (OwlLiteral)_owlGraph.AddLiteral(literalValue,langID,datatypeUri);

                    rEdge.ChildNode.AttachChildEdge(childEdge);
                    //attach it to the edge
                    childEdge.AttachChildNode(childLiteral);
                    //add the edge to the graph
                    _owlGraph.AddEdge(childEdge);
                }
            }
        }
Esempio n. 11
0
        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: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#";

            OwlOntology o = new OwlOntology(baseUri + "testOntology");
            ontology.Nodes.Add(o);

            OwlClass a = new OwlClass(baseUri + "ClassA");
            ontology.Nodes.Add(a);

            OwlClass b = new OwlClass(baseUri + "ClassB");
            ontology.Nodes.Add(b);

            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");
        }
Esempio n. 12
0
        /// <summary>
        /// Implementation of an OwlEdge.
        /// </summary>
        /// <param name="edge">The actual edge to be visited</param>
        /// <param name="parent">The parent object (node) of the edge</param>
        public override void Visit(OwlEdge edge, Object parent)
        {
            XmlElement parentElement = parent as XmlElement;

            if (parentElement != null)
            {
                Uri uri = new Uri(edge.ID);
                // Retrieve the local name from the uri
                string localName = uri.Fragment.Substring(1, uri.Fragment.Length - 1);
                // Get the path, up to the local name, from the uri
                string path = uri.GetLeftPart(UriPartial.Path) + "#";
                string prefix;
                // Check for the namespace of the edge in order to get the correct prefix
                if (path == OwlNamespaceCollection.OwlNamespace)
                {
                    prefix = OwlNamespaceCollection.OwlNamespacePrefix;
                }
                else if (path == OwlNamespaceCollection.RdfNamespace)
                {
                    prefix = OwlNamespaceCollection.RdfNamespacePrefix;
                }
                else if (path == OwlNamespaceCollection.RdfSchemaNamespace)
                {
                    prefix = OwlNamespaceCollection.RdfSchemaNamespacePrefix;
                }
                else
                {
                    // If the namespace of the edge is something else, then look for it
                    prefix = "";
                    if (path != _baseUri)
                    {
                        // Search for the prefix of this individual
                        int pos = _namespaces[path].IndexOf(':');
                        if (pos != -1)
                        {
                            prefix = _namespaces[path].Substring(++pos);
                        }
                    }
                }

                string qualifiedName = (prefix.Length != 0) ? (prefix + ":" + localName) : localName;
                // At this point we will not generate the rdf:type edges.
                XmlElement edgeElement = _owlDocument.CreateElement(qualifiedName, path);

                // Check to see if the child node is an anonymous one or not. If it is, then further
                // process that node, otherwise just reference it by name.
                OwlNode node = (OwlNode)edge.ChildNode;
                if (node.IsAnonymous() || node.IsLiteral())
                {
                    node.Accept(this, edgeElement);
                }
                else
                {
                    // Add the name as one of its attributes
                    XmlAttribute nameAttribute = _owlDocument.CreateAttribute("rdf", "resource", OwlNamespaceCollection.RdfNamespace);
                    nameAttribute.Value = GetNodeReference(node);
                    edgeElement.Attributes.Append(nameAttribute);
                }
                parentElement.AppendChild(edgeElement);
            }
        }
 /// <summary>
 /// Create a node from the rdf:resource attribute and attach it to a given edge as a child
 /// </summary>
 /// <param name="node">The XmlNode that contains the rdf:resource attribute.</param>
 /// <param name="rEdge">The edge to which the new childnode must be added.</param>
 /// <param name="resourceUri">The URI specified by the rdf:resource attribute.</param>
 /// <remarks>If the specified Uri is null or empty a new blank node URI is created. 
 /// If it is a relative URI then it is converted to an absolute URI by prefixing it with the value given by xml:base</remarks>
 private void ProcessRdfResource(XmlNode node, OwlEdge rEdge, string resourceUri)
 {
     string nodeID = QualifyResource(resourceUri,GetXmlBase(node));
     OwlNode rNode = (OwlNode)_owlGraph.AddNode(nodeID);
     rEdge.AttachChildNode(rNode);
 }
 /// <summary>
 /// Process the rdf:nodeID attribute found on the OWL edge
 /// </summary>
 /// <param name="rEdge">The edge to which the rdf:nodeID attribute must be applied</param>
 /// <param name="baseNodeID">The ID specified by the rdf:nodeID attribute</param>
 private void ProcessRdfNodeID(OwlEdge rEdge, string baseNodeID)
 {
     if(!IsXmlName(baseNodeID))
         OnError(baseNodeID+" is not an XML name");
     OwlNode rNode = (OwlNode)_owlGraph.AddNode(GetBlankNodeUri(baseNodeID));
     rEdge.AttachChildNode(rNode);
 }
        /// <summary>
        /// Implementation of an OwlEdge.
        /// </summary>
        /// <param name="edge">The actual edge to be visited</param>
        /// <param name="parent">The parent object (node) of the edge</param>
        public override void Visit(OwlEdge edge, Object parent)
        {
            XmlElement parentElement = parent as XmlElement;
            if(parentElement != null)
            {
                Uri uri = new Uri(edge.ID);
                // Retrieve the local name from the uri
                string localName = uri.Fragment.Substring(1, uri.Fragment.Length-1);
                // Get the path, up to the local name, from the uri
                string path = uri.GetLeftPart(UriPartial.Path) + "#";
                string prefix;
                // Check for the namespace of the edge in order to get the correct prefix
                if(path == OwlNamespaceCollection.OwlNamespace)
                    prefix = OwlNamespaceCollection.OwlNamespacePrefix;
                else if(path == OwlNamespaceCollection.RdfNamespace)
                    prefix = OwlNamespaceCollection.RdfNamespacePrefix;
                else if(path == OwlNamespaceCollection.RdfSchemaNamespace)
                    prefix = OwlNamespaceCollection.RdfSchemaNamespacePrefix;
                else
                {
                    // If the namespace of the edge is something else, then look for it
                    prefix = "";
                    if(path != _baseUri)
                    {
                        // Search for the prefix of this individual
                        int pos = _namespaces[path].IndexOf(':');
                        if(pos != -1)
                        {
                            prefix = _namespaces[path].Substring(++pos);
                        }
                    }
                }

                string qualifiedName = (prefix.Length != 0) ? (prefix + ":" + localName) : localName;
                // At this point we will not generate the rdf:type edges.
                    XmlElement edgeElement = _owlDocument.CreateElement(qualifiedName, path);

                    // Check to see if the child node is an anonymous one or not. If it is, then further
                    // process that node, otherwise just reference it by name.
                    OwlNode node = (OwlNode)edge.ChildNode;
                    if(node.IsAnonymous() || node.IsLiteral())
                        node.Accept(this, edgeElement);
                    else
                    {
                        // Add the name as one of its attributes
                        XmlAttribute nameAttribute = _owlDocument.CreateAttribute("rdf", "resource", OwlNamespaceCollection.RdfNamespace);
                        nameAttribute.Value = GetNodeReference(node);
                        edgeElement.Attributes.Append(nameAttribute);
                    }
                    parentElement.AppendChild(edgeElement);
            }
        }
        private IOwlIndividual CalculateGatewayDirection(Shape shape, IOwlIndividual individual)
        {
            /*
             * formal Table 8.46
             * Unspecified: There are no constraints. The Gateway MAY have any number of incoming and outgoing Sequence Flows.
             * Converging: This Gateway MAY have multiple incoming Sequence Flows but MUST have no more than one (1) outgoing Sequence Flow.
             * Diverging: This Gateway MAY have multiple outgoing Sequence Flows but MUST have no more than one (1) incoming Sequence Flow.
             * Mixed: This Gateway contains multiple outgoing and multiple incoming Sequence Flows.
            */

            int incomingNumber = shape.GluedShapes(VisGluedShapesFlags.visGluedShapesIncoming1D, "", null).Length;
            int outgoingNumber = shape.GluedShapes(VisGluedShapesFlags.visGluedShapesOutgoing1D, "", null).Length;

            OwlIndividual gatewayDirection;

            if (incomingNumber > 1 && outgoingNumber <= 1)
            {
                //Converging
                gatewayDirection = (OwlIndividual)this._graph.Nodes[ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, "Converging")];

            }
            else if (incomingNumber <= 1 && outgoingNumber > 1)
            {
                //Diverging
                gatewayDirection = (OwlIndividual)this._graph.Nodes[ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, "Diverging")];
            }
            else if (incomingNumber > 1 && outgoingNumber > 1)
            {
                //Mixed
                gatewayDirection = (OwlIndividual)this._graph.Nodes[ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, "Mixed")];
            }
            else
            {
                //Unspecified
                gatewayDirection = (OwlIndividual)this._graph.Nodes[ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, "Unspecified")];

            }

            IOwlEdge hasGatewayDirection = new OwlEdge(ToolKit.GetFullName(Constant.BPMN_TARGET_NAMESPACE, "hasGatewayDirection"));
            hasGatewayDirection.ChildNode = gatewayDirection;

            individual.AttachChildEdge(hasGatewayDirection);

            return individual;
        }
Esempio n. 17
0
 /// <summary>
 /// Implementation of the visit function to generate some output, used in the visitor pattern
 /// </summary>
 /// <param name="edge">The actual edge which needs to be generated</param>
 /// <param name="parent">The parent object of the edge</param>
 public abstract void Visit(OwlEdge edge, Object parent);
        /// <summary>
        /// Processes the rdf:parseType attribute
        /// </summary>
        /// <param name="node">The XML Node on which the attribute appears</param>
        /// <param name="rEdge">The edge to which the attribute must be applied</param>
        /// <param name="parseType">The parse type as specified by the value of the attribute</param>
        private void ProcessRdfParseType(XmlNode node, OwlEdge rEdge, string parseType)
        {
            this.OnMessage("Parsing a parseType");
            if(parseType == "Resource")
            {
                //its an rdf:parseType="Resource" so we must now parse its children
                //the children of this xmlNode are now EDGES in the RDF graph that
                //extend out from the dest node of this edge i.e. the rdfNode created above

                //create a new node that will be the child of this edge
                //create a new node ID
                OwlNode rNode = (OwlNode)_owlGraph.AddNode(GetBlankNodeUri(null));
                //attach this node to the edge
                rEdge.AttachChildNode(rNode);
                this.OnMessage("Parsing a parseType: Resource");
                if(node.HasChildNodes)
                {
                    int count = node.ChildNodes.Count;
                    for(int i=0;i<count;i++)
                    {
                        this.OnMessage("Going to parse the first child: " + node.ChildNodes[i].OuterXml.ToString());
                        ProcessEdge(node.ChildNodes[i], rNode);
                    }
                }
            }
            else if(parseType == "Literal")
            {
                //its an rdf:parseType="Literal" so all the xml below this node
                //will be the content of the dest node i.e. rdfNode
                //create a new node that will be the child of this edge
                //create a new node ID
                string literalValue = node.InnerXml;
                string datatypeUri = GetDatatypeUri(node);
                if(datatypeUri == null)
                    datatypeUri = "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral";
                OwlLiteral literal = (OwlLiteral)_owlGraph.AddLiteral(literalValue,rEdge.LangID,datatypeUri);
                //attach this node to the edge
                rEdge.AttachChildNode(literal);
            }
            else if(parseType == "Collection")
            {
                //its a Collection so make a cons list
                //get the children of this node
                OwlNode rNode = BuildCollection(node);
                //connect the collection to the edge
                rEdge.AttachChildNode(rNode);
            }
            else
            {
                OnError("Unknown parseType "+parseType);
            }
        }
Esempio n. 19
0
        /// <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);
                    }
                }
            }
        }
 /// <summary>
 /// Adds an OWL Resource of type owl:TransitiveProperty to the graph</summary>
 /// <param name="nodeUri">The Uri of the resource.</param>
 /// <returns>Returns a reference to the newly added resource.</returns>
 /// <exception cref="UriFormatException">The specified nodeUri is not a well formed Uri.</exception>
 private OwlNode AddTransitivePropertyToGraph(string nodeUri)
 {
     OwlNode node = AddObjectPropertyToGraph(nodeUri);
     OwlNode typeNode = (OwlNode)_owlGraph.AddNode(OwlNamespaceCollection.OwlNamespace+"TransitiveProperty");
     OwlEdge typeEdge = new OwlEdge(OwlNamespaceCollection.RdfNamespace+"type");
     _owlGraph.AddEdge(typeEdge);
     typeEdge.AttachChildNode(typeNode);
     node.AttachChildEdge(typeEdge);
     return node;
 }
 /// <summary>
 /// Implementation of the visit function to generate some output, used in the visitor pattern
 /// </summary>
 /// <param name="edge">The actual edge which needs to be generated</param>
 /// <param name="parent">The parent object of the edge</param>
 public abstract void Visit(OwlEdge edge, Object parent);