예제 #1
0
        /* Function extracts the RdfProperty data from an XmlNode. Function expects
         * specific RdfProperty information available.
         *
         * Inputs: node - the XmlNode to extract RdfProperty data
         *
         * Return values: the RdfProperty instance containing the node data
         */
        private RdfProperty GetNodeData(XmlNode propertyNode)
        {
            if (propertyNode == null)
            {
                throw new ArgumentNullException("propertyNode", "Cannot be null");
            }

            RdfProperty data = new RdfProperty();

            // Set name
            data.Name = propertyNode.Attributes[DamlConstants.RDF_ID].Value;
            // Set Domain
            data.Domain = propertyNode.SelectSingleNode(DamlConstants.RDFS_DOMAIN, m_mgr).Attributes[DamlConstants.RDF_RESOURCE].Value;
            // Set Range
            data.Range = propertyNode.SelectSingleNode(DamlConstants.RDFS_RANGE, m_mgr).Attributes[DamlConstants.RDF_RESOURCE].Value;
            // Set SubPropertyOf
            data.SubPropertyOf = propertyNode.SelectSingleNode(DamlConstants.RDFS_SUBPROPERTYOF, m_mgr).Attributes[DamlConstants.RDF_RESOURCE].Value;

            // Fill in sameValueAs data (if any)
            XmlNode sameValueAsNode = propertyNode.SelectSingleNode(DamlConstants.DAML_SAMEVALUESAS, m_mgr);

            if (sameValueAsNode != null)
            {
                data.SameValueAs = sameValueAsNode.Attributes[DamlConstants.RDF_RESOURCE].Value;
            }

            return(data);
        }
        private void AddRdfProperties(ref XmlDocument doc, RdfProperty[] arrData, enuIOPEType restrictionType)
        {
            XmlNode root = doc.DocumentElement;

            for (int i = 0; i < arrData.Length; i++)
            {
                RdfProperty prop    = (RdfProperty)arrData[i];
                XmlDocument propDoc = new XmlDocument();
                propDoc.LoadXml(prop.ToXml());
                XmlNode propDocRoot  = propDoc.DocumentElement;
                XmlNode propertyNode = doc.ImportNode(propDocRoot.FirstChild, true);

                // Get restrictions on property (if any)
                DamlRestriction[] arrRestrictions = this.GetRestrictions(restrictionType);

                for (int j = 0; j < arrRestrictions.Length; j++)
                {
                    if (arrRestrictions[j].Owner == prop.Name)
                    {
                        // Create subClassOf node
                        XmlNode subClassOfNode = doc.CreateNode(XmlNodeType.Element, DamlConstants.RDFS_SUBCLASSOF, DamlConstants.RDFS_NS_URI);
                        // Create a node for each restriction (child of subClassOfNode)
                        XmlNode restrictionNode = doc.CreateNode(XmlNodeType.Element, DamlConstants.DAML_RESTRICTION, DamlConstants.DAML_NS_URI);
                        // Fill in restrictionNode data

                        // Add cardinality attribute if value has been set
                        if (arrRestrictions[j].Cardinality != DamlRestriction.NO_CARDINALITY)
                        {
                            // Create attribute
                            XmlAttribute cardinalityAtt = doc.CreateAttribute(DamlConstants.DAML_CARDINALITY, DamlConstants.DAML_NS_URI);
                            // Set attribute value
                            cardinalityAtt.Value = arrRestrictions[j].Cardinality.ToString();
                            // Add attribute to node
                            restrictionNode.Attributes.Append(cardinalityAtt);
                        }

                        // Create onPropertyNode
                        XmlNode onPropertyNode = doc.CreateNode(XmlNodeType.Element, DamlConstants.DAML_ON_PROPERTY, DamlConstants.DAML_NS_URI);
                        // Create onProperty attribute
                        XmlAttribute onPropertyAtt = doc.CreateAttribute(DamlConstants.RDF_RESOURCE, DamlConstants.RDF_NS_URI);
                        // Set attribute value
                        onPropertyAtt.Value = arrRestrictions[j].OnProperty;
                        // Add attribute to node
                        onPropertyNode.Attributes.Append(onPropertyAtt);

                        // Add onPropertyNode to restrictionNode
                        restrictionNode.AppendChild(onPropertyNode);
                        // Add restrictionNode to subClassOfNode
                        subClassOfNode.AppendChild(restrictionNode);
                        //Add subClassOfNode to root
                        propertyNode.AppendChild(subClassOfNode);
                    }
                }

                // Add rdf:Property to root of document
                root.AppendChild(propertyNode);
            }
        }
예제 #3
0
        private DamlTypeDefinition[] FindTypeDefinitions(RdfProperty data)
        {
            ArrayList lstDefinitions = new ArrayList();

            if (!data.Range.ToLower().StartsWith("http://"))
            {
                DamlTypeDefinition defnRdf = this.FindTypeDefintionInRdfProperty(data.Range.TrimStart(new char[] { '#' }));
                if (defnRdf != null)
                {
                    lstDefinitions.Add(defnRdf);
                }

                DamlTypeDefinition defnClass = this.FindTypeDefinitionInDamlClass(data.Range.TrimStart(new char[] { '#' }));
                if (defnClass != null)
                {
                    lstDefinitions.Add(defnClass);
                }
            }

            if (!data.SameValueAs.ToLower().StartsWith("http://"))
            {
                DamlTypeDefinition defnRdf = this.FindTypeDefintionInRdfProperty(data.SameValueAs.TrimStart(new char[] { '#' }));
                if (defnRdf != null)
                {
                    lstDefinitions.Add(defnRdf);
                }

                DamlTypeDefinition defnClass = this.FindTypeDefinitionInDamlClass(data.SameValueAs.TrimStart(new char[] { '#' }));
                if (defnClass != null)
                {
                    lstDefinitions.Add(defnClass);
                }
            }

            return((DamlTypeDefinition[])lstDefinitions.ToArray(typeof(DamlTypeDefinition)));
        }
예제 #4
0
        /* Function retrieves all the interesting data about a process given its name and
         * type.
         *
         * Interesting data:
         * Inputs, Outputs, Preconditions, Effects, Parameters, ConditionalOutputs,
         * Co-Conditions, Sub Processes (if process is a composite process)
         *
         * Inputs: strProcessName - named process
         *		   processType - process type (atomic, simple, composite)
         *
         * Return value: DamlProcess containing all the relevant data
         */
        public DamlProcess GetProcessData(string strProcessName, enuProcessType processType)
        {
            DamlProcess retVal = new DamlProcess();

            XmlNode root       = m_doc.DocumentElement;
            string  strBaseUri = GetNamespaceBaseUri(DamlConstants.PROCESS_NS);
            string  strUri     = "";

            strUri = strBaseUri;

            switch (processType)
            {
            case enuProcessType.AtomicProcess: strUri += DamlConstants.DAML_ATOMIC_PROCESS;
                break;

            case enuProcessType.CompositeProcess: strUri += DamlConstants.DAML_COMPOSITE_PROCESS;
                break;

            case enuProcessType.SimpleProcess: strUri += DamlConstants.DAML_SIMPLE_PROCESS;
                break;

            default:  throw new ArgumentException("Invalid processType value");
            }
            ;

            string strXPath = DamlConstants.DAML_CLASS + "[@" + DamlConstants.RDF_ID + "='" + strProcessName + "']" + "/" + DamlConstants.RDFS_SUBCLASSOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strUri + "']";

            XmlNode processNode = root.SelectSingleNode(strXPath, m_mgr).ParentNode;

            if (processNode == null)
            {
                throw new Exception("Process node found");
            }

            // Set process name
            retVal.Name = processNode.Attributes[DamlConstants.RDF_ID].Value;
            // Set process type
            retVal.ProcessType = processType;

            // Get Process restrictions - these are actually input restrictions on
            // the process
            DamlRestriction[] arrProcessRestrict = this.GetRestrictions(strProcessName);
            retVal.AddRestriction(enuIOPEType.Input, arrProcessRestrict);

            // Get inputs from querying RdfProperty nodes in document
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.INPUT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            XmlNodeList lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddInput(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Input;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get additional inputs from the process node itself
            // they may be hidden under restictions tagged with
            // daml:sameValueAs
            strXPath = DamlConstants.DAML_CLASS + "[@" + DamlConstants.RDF_ID + "='" + retVal.Name + "']" + "/" + DamlConstants.RDFS_SUBCLASSOF + "/" + DamlConstants.DAML_RESTRICTION + "/" + DamlConstants.DAML_ON_PROPERTY + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.INPUT + "']" + "/" + "following-sibling::" + DamlConstants.DAML_SAMEVALUESAS;
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                string strSameValueAs = node.Attributes[DamlConstants.RDF_RESOURCE].Value;
                strSameValueAs = strSameValueAs.Trim(new char[] { '#' });

                // Go get RdfProperty data
                strXPath = DamlConstants.RDF_PROPERTY + "[@" + DamlConstants.RDF_ID + "='" + strSameValueAs + "']" + "/" + DamlConstants.RDFS_DOMAIN;
                XmlNode domainNode = root.SelectSingleNode(strXPath, m_mgr);

                // Add to list of inputs
                if (domainNode != null)
                {
                    RdfProperty data = GetNodeData(domainNode.ParentNode);
                    retVal.AddInput(data);

                    // Get restrictions (if any)
                    enuIOPEType       restrictionType = enuIOPEType.Input;
                    DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                    retVal.AddRestriction(restrictionType, arrRestrict);
                    retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
                }
            }

            // Get outputs
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.OUTPUT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddOutput(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Output;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get preconditions
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.PRECONDITION + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddPrecondition(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Precondition;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get effects
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.EFFECT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddEffect(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Effect;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get conditional outputs
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.CONDITIONAL_OUTPUT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddConditionalOutput(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.ConditionalOutput;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get co-conditions
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.CO_CONDITION + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddCoCondition(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.CoCondition;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get co-outputs
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.CO_OUTPUT + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddCoOutput(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.CoOutput;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // Get parameters
            strXPath = DamlConstants.RDF_PROPERTY + "/" + DamlConstants.RDFS_SUBPROPERTYOF + "[@" + DamlConstants.RDF_RESOURCE + "='" + strBaseUri + DamlConstants.PARAMETER + "']" + "/" + "following-sibling::" + DamlConstants.RDFS_DOMAIN + "[@" + DamlConstants.RDF_RESOURCE + "='#" + strProcessName + "']";
            lstNodes = root.SelectNodes(strXPath, m_mgr);

            foreach (XmlNode node in lstNodes)
            {
                RdfProperty data = GetNodeData(node.ParentNode);
                retVal.AddParameter(data);

                // Get restrictions (if any)
                enuIOPEType       restrictionType = enuIOPEType.Parameter;
                DamlRestriction[] arrRestrict     = this.GetRestrictions(data.Name);
                retVal.AddRestriction(restrictionType, arrRestrict);
                retVal.AddDataTypeDefinition(this.FindTypeDefinitions(data));
            }

            // If we are dealing with a complex process we must go get
            // the substeps - need to get process:<type> data
            if (processType == enuProcessType.CompositeProcess)
            {
                retVal.SubTaskType = GetProcessSubTaskType(retVal.Name);
                retVal.AddSubProcess(GetSubProcesses(retVal.Name));
            }
            return(retVal);
        }
 /* Procedure Adds a parameter to a DamlProcess
  *
  * Inputs: data - RdfProperty details of the parameter
  */
 public void AddParameter(RdfProperty data)
 {
     m_arrParameters.Add(data);
 }
 /* Procedure Adds a co-output to a DamlProcess
  *
  * Inputs: data - RdfProperty details of the co-output
  */
 public void AddCoOutput(RdfProperty data)
 {
     m_arrCoOutputs.Add(data);
 }
 /* Procedure Adds a co-condition to a DamlProcess
  *
  * Inputs: data - RdfProperty details of the co-condition
  */
 public void AddCoCondition(RdfProperty data)
 {
     m_arrCoConditions.Add(data);
 }
 /* Procedure Adds a conditional output to a DamlProcess
  *
  * Inputs: data - RdfProperty details of the conditional output
  */
 public void AddConditionalOutput(RdfProperty data)
 {
     m_arrConditionalOutputs.Add(data);
 }
 /* Procedure Adds an effect to a DamlProcess
  *
  * Inputs: data - RdfProperty details of the effect
  */
 public void AddEffect(RdfProperty data)
 {
     m_arrEffects.Add(data);
 }
 /* Procedure Adds a precondition to a DamlProcess
  *
  * Inputs: data - RdfProperty details of the precondition
  */
 public void AddPrecondition(RdfProperty data)
 {
     m_arrPreconditions.Add(data);
 }
 /* Procedure Adds an input to a DamlProcess
  *
  * Inputs: data - RdfProperty details of the input
  */
 public void AddInput(RdfProperty data)
 {
     m_arrInputs.Add(data);
 }