예제 #1
0
 public Boolean OwnsNodeItem(NodeItem ni)
 {
     return(this.nodes.Contains(ni));
 }
예제 #2
0
        public void InflateAndValidate(OntologyInfo oInfo)
        {
            if (oInfo == null)
            {
                return;
            }                              // nothing to do.

            List <PropertyItem> newProps = new List <PropertyItem>();
            List <NodeItem>     newNodes = new List <NodeItem>();

            // build a hash of suggested properties for this class
            Dictionary <String, PropertyItem> propItemHash = new Dictionary <String, PropertyItem>();

            foreach (PropertyItem p in this.props)
            {
                propItemHash.Add(p.GetUriRelationship(), p);
            }

            // build a hash of suggested nodes for this class
            Dictionary <String, NodeItem> nodeItemHash = new Dictionary <String, NodeItem>();

            foreach (NodeItem n in this.nodes)
            {
                nodeItemHash.Add(n.GetKeyName(), n);
            }

            // get oInfo's version of the property list
            OntologyClass ontClass = oInfo.GetClass(this.GetFullUriName());

            if (ontClass == null)
            {
                throw new Exception("Class does not exist in the model: " + this.GetFullUriName());
            }

            List <OntologyProperty> ontProps = oInfo.GetInheritedProperies(ontClass);

            // loop through oInfo's version
            foreach (OntologyProperty oProp in ontProps)
            {
                String oPropURI     = oProp.GetNameStr();
                String oPropKeyName = oProp.GetNameStr(true);

                // if the ontology property is one of the prop parameters, check it over
                if (propItemHash.ContainsKey(oPropURI))
                {
                    PropertyItem propItem = propItemHash[oPropURI];
                    if (!propItem.GetValueTypeURI().ToLower().Equals(oProp.GetRangeStr().ToLower()))
                    {   // something broke. panic.
                        throw new Exception(String.Format("Property %s range of %s doesn't match model range of %s", oPropURI, propItem.GetValueTypeURI(), oProp.GetRangeStr()));
                    }

                    // everythign was okay. add the propItem
                    newProps.Add(propItem);
                    propItemHash.Remove(oPropURI);
                }
                // else ontology property is not in this Node.  AND its range is outside the model (it's a Property)
                // Inflate (create) it.
                else if (!oInfo.ContainsClass(oProp.GetRangeStr()))
                {
                    if (nodeItemHash.ContainsKey(oPropKeyName))
                    {
                        throw new Exception(String.Format("Node property %s has range %s in the nodegroup, which can't be found in model.", oPropURI, oProp.GetRangeStr()));
                    }

                    PropertyItem propItem = new PropertyItem(oProp.GetNameStr(true), oProp.GetRangeStr(true), oProp.GetRangeStr(false), oProp.GetNameStr(false));
                    newProps.Add(propItem);
                }
                // node, in Hash
                else if (nodeItemHash.ContainsKey(oPropKeyName))
                {
                    // regardless of the connection, check the range.
                    NodeItem nodeItem   = nodeItemHash[oPropKeyName];
                    String   nRangeStr  = nodeItem.GetUriValueType();
                    String   nRangeAbbr = nodeItem.GetValueType();

                    if (!nRangeStr.Equals(oProp.GetRangeStr()))
                    {
                        throw new Exception("Node property " + oPropURI + " range of " + nRangeStr + " doesn't match model range of " + oProp.GetRangeStr());
                    }
                    if (!nRangeAbbr.Equals(oProp.GetRangeStr()))
                    {
                        throw new Exception("Node property " + oPropURI + " range abbreviation of " + nRangeAbbr + " doesn't match model range of " + oProp.GetRangeStr(true));
                    }

                    // if connected:
                    if (nodeItem.GetConnected())
                    {   // check the full domain.
                        String nDomainStr = nodeItem.GetUriConnectBy();
                        if (!nDomainStr.Equals(oProp.GetNameStr()))
                        {
                            throw new Exception("Node property " + oPropURI + " domain of " + nDomainStr + " doesn't match model domain of " + oProp.GetNameStr());
                        }

                        // check all connected snode classes
                        OntologyClass nRangeClass = oInfo.GetClass(nRangeStr);

                        List <Node> snodeList = nodeItem.GetNodeList();
                        foreach (Node nd in snodeList)
                        {
                            String        snodeURI   = nd.GetUri();
                            OntologyClass snodeClass = oInfo.GetClass(snodeURI);

                            if (snodeClass == null)
                            {
                                throw new Exception("Node property " + oPropURI + " is connected to node with class " + snodeURI + " which can't be found in model");
                            }
                            if (!oInfo.ClassIsA(snodeClass, nRangeClass))
                            {
                                throw new Exception("Node property " + oPropURI + " is connected to node with class " + snodeURI + " which is not a type of " + nRangeStr + " in model");
                            }
                        }
                    }
                    // all is okay: add the propItem
                    newNodes.Add(nodeItem);
                    nodeItemHash.Remove(oPropKeyName);
                }
                else
                {   // new node
                    NodeItem nodeItem = new NodeItem(oProp.GetNameStr(true), oProp.GetRangeStr(true), oProp.GetRangeStr(false));
                    newNodes.Add(nodeItem);
                }
            }

            if (propItemHash.Count != 0)
            {
                throw new Exception("Property does not exist in the model: " + propItemHash.Keys.ToString());
            }
            if (nodeItemHash.Count != 0)
            {
                throw new Exception("Node property does not exist in the model: " + nodeItemHash.Keys.ToString());
            }

            this.props = newProps;
            this.nodes = newNodes;
        }