Exemplo n.º 1
0
        public ICollection <SADIService> getAllServices(int offset, int limit)
        {
            ICollection <SADIService> services = new List <SADIService>();

            string query =
                "PREFIX sadi: <http://sadiframework.org/ontologies/sadi.owl#> \r\n" +
                "PREFIX mygrid: <http://www.mygrid.org.uk/mygrid-moby-service#> \r\n" +
                "SELECT * \r\n" +
                "WHERE {\r\n" +
                "   ?serviceURI a sadi:Service . \r\n" +
                "	?serviceURI mygrid:hasServiceNameText ?name . \r\n"+
                "	?serviceURI mygrid:hasServiceDescriptionText ?description . \r\n"+
                "	?serviceURI mygrid:hasOperation ?op . \r\n"+
                "	?op mygrid:inputParameter ?input . \r\n"+
                "	?input a mygrid:parameter . \r\n"+
                "	?input mygrid:objectType ?inputClassURI . \r\n"+
                // instanceQuery is not optional here because we only want services
                // whose input instances can be dynamically discovered...
                "   ?inputClassURI sadi:instanceQuery ?query . \r\n" +
                "}";

            foreach (JsonData binding in executeQuery(query))
            {
                SADIService service = new SADIService(
                    getSPARQLBindingAsString(binding, "serviceURI"),
                    getSPARQLBindingAsString(binding, "name"),
                    getSPARQLBindingAsString(binding, "description"),
                    getSPARQLBindingAsString(binding, "inputClassURI"));
                service.inputInstanceQuery = getSPARQLBindingAsString(binding, "query");
                services.Add(service);
            }
            return(services);
        }
        internal static String getDescription(SADIService service)
        {
            StringBuilder buf = new StringBuilder();

            buf.Append("  (");
            buf.Append(service.uri);
            buf.Append(")\r\n  ");
            if (service.description != null)
            {
                buf.Append(service.description);
            }
            else
            {
                buf.Append("No description.");
            }
            if (service.properties.Count > 0)
            {
                buf.Append("\r\n  properties attached: ");
                foreach (PropertyRestriction r in service.properties)
                {
                    buf.Append("\r\n      ");
                    buf.Append(r.ToString());
                }
            }
            return(buf.ToString());
        }
Exemplo n.º 3
0
        public SADIService getService(string serviceURI)
        {
            string query =
                "PREFIX sadi: <http://sadiframework.org/ontologies/sadi.owl#> \r\n" +
                "PREFIX mygrid: <http://www.mygrid.org.uk/mygrid-moby-service#> \r\n" +
                "SELECT * \r\n" +
                "WHERE {\r\n" +
                "   ?serviceURI a sadi:Service . \r\n" +
                "	?serviceURI mygrid:hasServiceNameText ?name . \r\n"+
                "	?serviceURI mygrid:hasServiceDescriptionText ?description . \r\n"+
                "	?serviceURI mygrid:hasOperation ?op . \r\n"+
                "	?op mygrid:inputParameter ?input . \r\n"+
                "	?input a mygrid:parameter . \r\n"+
                "	?input mygrid:objectType ?inputClassURI . \r\n"+
                // instanceQueryPattern is optional here because we're matching by
                // direct type and there's no need for dynamic discovery...
                "   OPTIONAL { ?inputClassURI sadi:instanceQuery ?query } . \r\n" +
                "}";

            query = query.Replace("?serviceURI", "<" + serviceURI + ">");

            foreach (JsonData binding in executeQuery(query))
            {
                SADIService service = new SADIService(
                    getSPARQLBindingAsString(binding, "serviceURI"),
                    getSPARQLBindingAsString(binding, "name"),
                    getSPARQLBindingAsString(binding, "description"),
                    getSPARQLBindingAsString(binding, "inputClassURI"));
                service.inputInstanceQuery = getSPARQLBindingAsString(binding, "query");
                return(service);
            }
            throw new ArgumentException(serviceURI + " is not a registered service");
        }
Exemplo n.º 4
0
        public void addPropertyRestrictions(SADIService service)
        {
            if (service.properties.Count > 0)
            {
                SADIHelper.debug("SADIRegistry", "addPropertyRestrictions called twice on same service", service);
                return;
            }

            String query =
                "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \r\n" +
                "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \r\n" +
                "PREFIX owl: <http://www.w3.org/2002/07/owl#> \r\n" +
                "PREFIX sadi: <http://sadiframework.org/ontologies/sadi.owl#> \r\n" +
                "PREFIX mygrid: <http://www.mygrid.org.uk/mygrid-moby-service#> \r\n" +
                "SELECT DISTINCT ?onPropertyURI ?onPropertyLabel ?valuesFromURI ?valuesFromLabel \r\n" +
                "WHERE {\r\n" +
                "	<"+ service.uri + "> sadi:decoratesWith ?decoration . \r\n" +
                "	?decoration owl:onProperty ?onPropertyURI . \r\n"+
                "	OPTIONAL { ?onPropertyURI rdfs:label ?onPropertyLabel } .  \r\n"+
                "	OPTIONAL { \r\n"+
                "		?decoration owl:someValuesFrom ?valuesFromURI . \r\n"+
                "		OPTIONAL { ?valuesFromURI rdfs:label ?valuesFromLabel } \r\n"+
                "	} . \r\n"+
                "}";

            foreach (JsonData binding in executeQuery(query))
            {
                service.addProperty(
                    getSPARQLBindingAsString(binding, "onPropertyURI"),
                    getSPARQLBindingAsString(binding, "onPropertyLabel"),
                    getSPARQLBindingAsString(binding, "valuesFromURI"),
                    getSPARQLBindingAsString(binding, "valuesFromLabel"));
            }
        }
        internal void setService(SADIService service)
        {
            this.service = service;
            string name = getName(service);

            this.name.Text        = getName(service);
            this.description.Text = getDescription(service);
        }
 internal static String getName(SADIService service)
 {
     if (service.name != null)
     {
         return(service.name);
     }
     else
     {
         return("No name");
     }
 }
        private MemoryStore assembleInput(IEnumerable <IResource> selectedNodes, SADIService service)
        {
            MemoryStore input = new MemoryStore();

            foreach (IResource node in selectedNodes)
            {
                if (node is IEntity)
                {
                    service.assembleInput(input, node as IEntity, KE);
                }
            }
            return(input);
        }
Exemplo n.º 8
0
        public ICollection <SADIService> findServicesByInputClass(ICollection <String> types)
        {
            ICollection <SADIService> services = new List <SADIService>();

            if (types.Count == 0)
            {
                return(services);
            }

            string query =
                "PREFIX sadi: <http://sadiframework.org/ontologies/sadi.owl#> \r\n" +
                "PREFIX mygrid: <http://www.mygrid.org.uk/mygrid-moby-service#> \r\n" +
                "SELECT * \r\n" +
                "WHERE {\r\n" +
                "   ?serviceURI a sadi:Service . \r\n" +
                "	?serviceURI mygrid:hasServiceNameText ?name . \r\n"+
                "	?serviceURI mygrid:hasServiceDescriptionText ?description . \r\n"+
                "	?serviceURI mygrid:hasOperation ?op . \r\n"+
                "	?op mygrid:inputParameter ?input . \r\n"+
                "	?input a mygrid:parameter . \r\n"+
                "	?input mygrid:objectType ?inputClassURI . \r\n"+
                // instanceQueryPattern is optional here because we're matching by
                // direct type and there's no need for dynamic discovery...
                "   OPTIONAL { ?inputClassURI sadi:instanceQuery ?query } . \r\n";

            int n = 0;

            foreach (string type in types)
            {
                if (++n > 1)
                {
                    query += "	UNION \r\n";
                }
                query += "	{ ?input mygrid:objectType <"+ type + "> } \r\n";
            }

            query +=
                "}";

            foreach (JsonData binding in executeQuery(query))
            {
                SADIService service = new SADIService(
                    getSPARQLBindingAsString(binding, "serviceURI"),
                    getSPARQLBindingAsString(binding, "name"),
                    getSPARQLBindingAsString(binding, "description"),
                    getSPARQLBindingAsString(binding, "inputClassURI"));
                service.inputInstanceQuery = getSPARQLBindingAsString(binding, "query");
                services.Add(service);
            }
            return(services);
        }
Exemplo n.º 9
0
 private bool checkForInputInstances(SADIService service, IEnumerable <IResource> selectedNodes)
 {
     if (service.inputInstanceQuery != null)
     {
         string query = SADIHelper.convertConstructQuery(service.inputInstanceQuery);
         if (query != null)
         {
             foreach (ISPARQLResult result in KE.Graph.Query(query).Results)
             {
                 foreach (IResource node in selectedNodes)
                 {
                     if (node.Equals(result["input"]))
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
        private void InvokeServicesWorker_DoWork(object threadContext)
        {
            ServiceCallStatus call    = threadContext as ServiceCallStatus;
            SADIService       service = call.Data as SADIService;

            try
            {
                call.Status = "Assembling input";
                MasterWorker.ReportProgress(1, call);
                MemoryStore input = assembleInput(SelectedNodes, service);

                call.Status = "Calling service";
                call.Data   = "Assembled input:\r\n" + SemWebHelper.storeToString(input);
                MasterWorker.ReportProgress(33, call);
                Store output = service.invokeService(input);

                call.Status = "Storing output";
                call.Data   = "Received output:\r\n" + SemWebHelper.storeToString(output);
                MasterWorker.ReportProgress(66, call);
                ICollection <IStatement> statements = KE.Import(output);
                showNewStatements(statements);

                call.Status = "Done";
                call.Data   = service;
                MasterWorker.ReportProgress(100, call);
            }
            catch (Exception err)
            {
                SADIHelper.error("ServiceCall", "error calling service", service, err);
                call.Status = "Error";
                call.Data   = "Error:\r\n" + err.Message;
                MasterWorker.ReportProgress(100, call);
            }
            finally
            {
                Interlocked.Decrement(ref NumWorkers);
            }
        }