Exemple #1
0
        public async Task <OntologyInfo> ExecuteGetOntologyInfo(SparqlConnection connection)
        {   // get the ontology info information related to this connection.
            SimpleResultSet interrimResult = null;
            OntologyInfo    retval         = null;

            conf.SetServiceEndpoint(mappingPrefix + ontologyInfoDetailsEndpoint);
            String connectionJsonString = connection.ToJson().ToString();

            this.parameterJson.Add("jsonRenderedSparqlConnection", JsonValue.CreateStringValue(connectionJsonString));

            try
            {   // talk to the service to get the ontology info details.
                //JsonObject obj = (JsonObject)this.Execute().Result;
                JsonObject objExec = (JsonObject)(await this.Execute());

                interrimResult = SimpleResultSet.FromJson(objExec);
                interrimResult.ThrowExceptionIfUnsuccessful();
                // get the actual value from the results
                JsonObject obj = interrimResult.GetResultJsonObject("ontologyInfo");
                // build an oInfo from it.
                retval = new OntologyInfo();
                retval.AddJson(obj);
            }
            finally
            {
                conf.SetServiceEndpoint(null);
                this.parameterJson.Remove("jsonRenderedSparqlConnection");
            }
            // return the OntologyInfo
            return(retval);
        }
Exemple #2
0
        public void GetOntologyInfoFromService()
        {   // talk to the service and get an ontology info built.
            // set up
            RestClientConfig          rcc  = new RestClientConfig(protocol, serverAddress, onotologyInfoServicePort);
            OntologyInfoServiceClient oisc = new OntologyInfoServiceClient(rcc);

            String           sparqlConnectionJsonString = "{\"name\": \"pop music test\",\"domain\": \"http://\",\"model\": [{\"type\": \"virtuoso\",\"url\": \"http://fake-server:2420\",\"dataset\": \"http://research.ge.com/test/popmusic/model\"}],\"data\": [{\"type\": \"virtuoso\",\"url\": \"http://fake-server:2420\",\"dataset\": \"http://research.ge.com/test/popmusic/data\"}]}";
            SparqlConnection connect = new SparqlConnection(sparqlConnectionJsonString);

            OntologyInfo oInfo = oisc.ExecuteGetOntologyInfo(connect).Result;

            Assert.IsTrue(oInfo.GetNumberOfProperties() == 17);
            Assert.IsTrue(oInfo.GetNumberOfClasses() == 8);
            Assert.IsTrue(oInfo.GetNumberOfEnum() == 0);
        }
Exemple #3
0
        public static NodeGroup DeepCopy(NodeGroup source)
        {
            NodeGroup retval = new NodeGroup();

            retval.AddJsonEncodedNodeGroup(source.ToJson());

            // connection info
            SparqlConnection conn = new SparqlConnection();

            if (source.conn != null)
            {
                conn.FromJson(source.conn.ToJson());
                retval.SetSparqlConnection(conn);
            }
            return(retval);
        }
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            // attempt to use the connection details to request and Oinfo.
            String connectionText = this.connectionTextBox.Text;

            // check that it is not empty:
            if (connectionText == null || connectionText.Length == 0)
            {   // panic in some way. tell the user, i guess
                FlyoutBase.ShowAttachedFlyout(this.connectionTextBox);
                return;
            }
            else
            {
                // try to get the oInfo from the connection.
                if (this.oisc != null)
                {
                    Debug.WriteLine("about to try to get oInfo...");

                    SparqlConnection conn = new SparqlConnection(connectionText);
                    this.myConnection = conn;

                    Debug.WriteLine("have gotten a connection");
                    Debug.WriteLine("about to get the oInfo from service: " + oisc.GetConfig().GetServiceUrl());

                    this.oInfo = await this.GetMyOInfo(conn);

                    Debug.WriteLine("probably got the oInfo from service ");

                    Debug.WriteLine(oInfo.ToJson().ToString());

                    this.LoadListView();
                    this.queryNodeGroup  = new NodeGroup();
                    this.nodegroupCanvas = new NodeGroupCanvas(this.queryNodeGroup, this.NodeGroupCanvasControl);
                }
                else
                {   // send the flyout.
                    FlyoutBase.ShowAttachedFlyout(this.loadConnectionButton);
                }
            }
        }
        private async Task <OntologyInfo> GetMyOInfo(SparqlConnection conn)
        {
            OntologyInfo oInfoGathered = await this.oisc.ExecuteGetOntologyInfo(conn);

            return(oInfoGathered);
        }
        public void AddJson(JsonObject encodedOInfo)
        {
            // check the version:
            long version = 0;

            if (encodedOInfo.ContainsKey("version"))
            {
                version = (long)encodedOInfo.GetNamedNumber("version");
            }
            // check the version information now
            if (version > OntologyInfo.JSON_VERSION)
            {   // fail gracelessly
                throw new Exception("Can't decode OntologyInfo JSON with newer version > " + OntologyInfo.JSON_VERSION + " : found " + version);
            }

            // get the connection, if it exists and we care.
            if (encodedOInfo.ContainsKey("sparqlConn"))
            {   // set it up.
                JsonObject       connObj = encodedOInfo.GetNamedObject("sparqlConn");
                SparqlConnection connVal = new SparqlConnection(connObj.ToString());
                this.modelConnnection = connVal;
            }

            // get the oInfo block
            if (!encodedOInfo.ContainsKey("ontologyInfo"))
            {   // panic
                throw new Exception("encoded group does not include the ontologyInfo block and cannot be used.");
            }
            JsonObject oInfoBlock = encodedOInfo.GetNamedObject("ontologyInfo");

            // unpack the prefixews
            Dictionary <String, String> prefixHash = new Dictionary <String, String>();
            JsonArray prefixes = oInfoBlock.GetNamedArray("prefixes");

            for (int i = 0; i < prefixes.Count; i++)
            {
                JsonObject currPrefix = prefixes.GetObjectAt((uint)i);
                prefixHash.Add(currPrefix.GetNamedString("prefixId"), currPrefix.GetNamedString("prefix"));
            }

            // unpack everything else. this is a little different than in the java because we do not have to use the table load
            // logic. as a result, this may be more straightforward.

            // unpack the classes:

            JsonArray classArr = oInfoBlock.GetNamedArray("classList");

            for (int m = 0; m < classArr.Count; m++)
            {   // get each class and add them... and related values...
                JsonObject currClass = classArr.GetObjectAt((uint)m);
                String     fullUri   = Utility.Utility.UnPrefixUri(currClass.GetNamedString("fullUri"), prefixHash);
                JsonArray  subC      = currClass.GetNamedArray("subClasses");
                JsonArray  superC    = currClass.GetNamedArray("superClasses");
                JsonArray  comments  = currClass.GetNamedArray("comments");
                JsonArray  labels    = currClass.GetNamedArray("labels");
                JsonArray  direct    = currClass.GetNamedArray("directConnections");

                // find or create the class.
                OntologyClass curr = null;

                if (this.classHash.ContainsKey(fullUri))
                {   // get that one.
                    curr = classHash[fullUri];
                }
                else
                {   // create a new one
                    curr = new OntologyClass(fullUri);
                    this.classHash.Add(fullUri, curr);
                }

                // create the List of parent names
                for (int pi = 0; pi < superC.Count; pi++)
                {   // check and add the superclasses
                    String pn = Utility.Utility.UnPrefixUri(superC.GetStringAt((uint)pi), prefixHash);
                    // check that the parent exists. if not, make it.
                    if (!this.classHash.ContainsKey(pn))
                    {
                        OntologyClass parentClass = new OntologyClass(pn);
                        classHash.Add(pn, parentClass);
                    }

                    // add the parent.
                    curr.AddParentName(pn);
                }

                // get the comments.
                for (int com = 0; com < comments.Count; com++)
                {
                    String c = comments.GetStringAt((uint)com);
                    curr.AddAnnotationComment(c);
                }

                // get the labels.
                for (int lab = 0; lab < labels.Count; lab++)
                {
                    String l = labels.GetStringAt((uint)lab);
                    curr.AddAnnotationLabel(l);
                }

                // add the subclasses as well...
                List <OntologyClass> children = new List <OntologyClass>();
                for (int h = 0; h < subC.Count; h++)
                {   // check and add the subclasses
                    String        cn    = Utility.Utility.UnPrefixUri(subC.GetStringAt((uint)h), prefixHash);
                    OntologyClass child = null;
                    // check that it exists. if not, make it.
                    if (!this.classHash.ContainsKey(cn))
                    {
                        OntologyClass childClass = new OntologyClass(cn);
                        classHash.Add(cn, childClass);
                        child = childClass;
                    }
                    else
                    {
                        child = this.classHash[cn];
                    }
                    children.Add(child);
                }

                // if there were any entries, add this.
                if (children.Count > 0)
                {
                    this.subclassHash.Add(fullUri, children);
                }

                // handle the connections.
                List <OntologyPath> paths = new List <OntologyPath>();
                for (int b = 0; b < direct.Count; b++)
                {   // all the one-hop connections.
                    JsonObject jdir = direct.GetObjectAt((uint)b);
                    String     destinationClassUri = Utility.Utility.UnPrefixUri(jdir.GetNamedString("destinationClass"), prefixHash);
                    String     predicateUri        = Utility.Utility.UnPrefixUri(jdir.GetNamedString("predicate"), prefixHash);
                    String     startClassUri       = Utility.Utility.UnPrefixUri(jdir.GetNamedString("startClass"), prefixHash);

                    OntologyPath op = new OntologyPath(startClassUri);
                    op.AddTriple(startClassUri, predicateUri, destinationClassUri);

                    // add to the list
                    paths.Add(op);
                }

                if (paths.Count > 0)
                {   // we have some paths. add it.
                    this.connHash.Add(fullUri, paths);
                }

                // done with the classes.
            }

            // unpack the properties:

            JsonArray propertyArr = oInfoBlock.GetNamedArray("propertyList");

            for (int j = 0; j < propertyArr.Count; j++)
            {   // add each entry to the property list.
                JsonObject currPropJson = propertyArr.GetObjectAt((uint)j);

                String    fullUri  = Utility.Utility.UnPrefixUri(currPropJson.GetNamedString("fullUri"), prefixHash);
                JsonArray comments = currPropJson.GetNamedArray("comments");
                JsonArray labels   = currPropJson.GetNamedArray("labels");
                JsonArray domain   = currPropJson.GetNamedArray("domain");
                JsonArray range    = currPropJson.GetNamedArray("range");

                // get the (currently) single range.
                String rangeUri = Utility.Utility.UnPrefixUri(range.GetStringAt(0), prefixHash);
                // create the property
                OntologyProperty oProp = new OntologyProperty(fullUri, rangeUri);

                for (int di = 0; di < domain.Count; di++)
                {   // get the domain info and add it.
                    String domainUri = Utility.Utility.UnPrefixUri(domain.GetStringAt((uint)di), prefixHash);
                    // get the class in the domain.
                    OntologyClass domClass = this.classHash[domainUri];
                    domClass.AddProperty(oProp);
                }

                // add the labels.
                for (int li = 0; li < labels.Count; li++)
                {
                    String label = labels.GetStringAt((uint)li);
                    oProp.AddAnnotationLabel(label);
                }

                // add the comments
                for (int ci = 0; ci < comments.Count; ci++)
                {
                    String comment = comments.GetStringAt((uint)ci);
                    oProp.AddAnnotationComment(comment);
                }

                this.propertyHash.Add(fullUri, oProp);
            }

            // add the enumerations
            JsonArray enumerationArr = oInfoBlock.GetNamedArray("enumerations");

            for (int ei = 0; ei < enumerationArr.Count; ei++)
            {
                JsonObject enumVal = enumerationArr.GetObjectAt((uint)ei);

                String    fullUri  = Utility.Utility.UnPrefixUri(enumVal.GetNamedString("fullUri"), prefixHash);
                JsonArray children = enumVal.GetNamedArray("enumeration");

                List <String> childUris = new List <String>();
                for (int ci = 0; ci < children.Count; ci++)
                {
                    childUris.Add(Utility.Utility.UnPrefixUri(children.GetStringAt((uint)ci), prefixHash));
                }
                // add the list
                if (childUris.Count > 0)
                {
                    this.enumerationHash.Add(fullUri, childUris);
                }
            }
        }