예제 #1
0
        public override void Run(SelectableSource source, QueryResultSink resultsink)
        {
            if (!(query is SelectQuery))
                throw new InvalidOperationException("Only SELECT queries are supported by this method (" + query.GetType() + ").");

            // Perform the query
            SelectQuery squery = (SelectQuery)query;
            RdfSourceWrapper sourcewrapper = BindLogic(source);

            RdfBindingSet results;
            try {
                results = squery.execute(sourcewrapper);
            } catch (name.levering.ryan.sparql.common.QueryException e) {
                throw new QueryExecutionException("Error executing query: " + e.Message, e);
            }

            // Prepare binding objects
            java.util.List vars = results.getVariables();
            SparqlVariable[] svars = new SparqlVariable[vars.size()];
            SemWebVariable[] vars2 = new SemWebVariable[vars.size()];
            for (int i = 0; i < svars.Length; i++) {
                svars[i] = (SparqlVariable)vars.get(i);
                vars2[i] = new SemWebVariable(svars[i].getName());
            }

            // Initialize the result sink
            resultsink.Init(vars2); // set distinct and ordered

            // Set the comments
            resultsink.AddComments(queryString + "\n");
            resultsink.AddComments(sourcewrapper.GetLog());

            // Iterate the bindings
            java.util.Iterator iter = results.iterator();
            long ctr = -1, ctr2 = 0;
            while (iter.hasNext()) {
                RdfBindingRow row = (RdfBindingRow)iter.next();

                // Since SPARQL processing may be lazy-delayed,
                // add any new comments that might have been logged.
                resultsink.AddComments(sourcewrapper.GetLog());

                ctr++;

                if (ctr < ReturnStart && ReturnStart != -1) continue;

                Resource[] bindings = new Resource[vars2.Length];

                for (int i = 0; i < bindings.Length; i++) {
                    Resource r = sourcewrapper.ToResource(row.getValue(svars[i]));
                    r = sourcewrapper.Persist(r);
                    bindings[i] = r;
                }

                resultsink.AddComments(sourcewrapper.GetLog());

                resultsink.Add(new VariableBindings(vars2, bindings));

                ctr2++;
                if (ctr2 >= ReturnLimit && ReturnLimit != -1) break;
            }

            resultsink.AddComments(sourcewrapper.GetLog());

            // Close the result sink.
            resultsink.Finished();
        }
예제 #2
0
		public override void Run(SelectableSource targetModel, QueryResultSink result) {
			CheckInit();
			
			foreach (Statement s in novariablestatements)
				if (!targetModel.Contains(s))
					return;
			
			VariableBinding[] finalbindings = new VariableBinding[variables.Length];
			for (int i = 0; i < variables.Length; i++)
				finalbindings[i].Variable = variableEntities[i];
			
			result.Init(finalbindings, true, false);
			
			Debug("Begnning Query");
			
			BindingSet bindings = new BindingSet(this);
			for (int group = 0; group < statements.Length; group++) {
				bool ret = Query(group, bindings, targetModel);
				if (!ret) {
					// A false return value indicates the query
					// certainly failed -- a non-optional statement
					// failed to match at all.
					result.Finished();
					return;
				}
			}

			int ctr = -1;
			foreach (QueryResult r in bindings.Results) {
				Permutation permutation = new Permutation(r.Bindings);
				do {
					ctr++;
					if (ctr < ReturnStart) continue;
					for (int i = 0; i < variables.Length; i++)
						finalbindings[i].Target = permutation[i];
					result.Add(finalbindings);
					if (ReturnLimit != -1 && ctr == ReturnStart+ReturnLimit) break;	
				} while (permutation.Next());
				if (ReturnLimit != -1 && ctr == ReturnStart+ReturnLimit) break;	
			}

			
			result.Finished();
		}
예제 #3
0
        public override void Run(SelectableSource source, QueryResultSink resultsink)
        {
            if (!(query is SelectQuery))
            {
                throw new InvalidOperationException("Only SELECT queries are supported by this method (" + query.GetType() + ").");
            }

            // Perform the query
            SelectQuery squery = (SelectQuery)query;

            RdfSourceWrapper sourcewrapper = new RdfSourceWrapper(source, QueryMeta, this);

            MyLogicFactory logic = new MyLogicFactory();

            foreach (RdfFunction f in extFunctions)
            {
                logic.registerExternalFunction(
                    new URIWrapper(f.Uri),
                    new ExtFuncWrapper(sourcewrapper, f));
            }

            squery.bindLogic(logic);

            RdfBindingSet results;

            try {
                results = squery.execute(sourcewrapper);
            } catch (java.lang.Exception e) {
                throw new QueryExecutionException("Error executing query: " + e.Message, e);
            }

            // Prepare binding objects
            java.util.List    vars     = results.getVariables();
            VariableBinding[] bindings = new VariableBinding[vars.size()];
            SparqlVariable[]  svars    = new SparqlVariable[vars.size()];
            SemWebVariable[]  vars2    = new SemWebVariable[vars.size()];
            for (int i = 0; i < bindings.Length; i++)
            {
                svars[i]    = (SparqlVariable)vars.get(i);
                vars2[i]    = new SemWebVariable(svars[i].getName());
                bindings[i] = new VariableBinding(vars2[i], null);
            }

            // Initialize the result sink
            resultsink.Init(bindings, false, false);             // set distinct and ordered

            // Set the comments
            resultsink.AddComments(queryString + "\n");
            resultsink.AddComments(sourcewrapper.GetLog());

            // Iterate the bindings
            java.util.Iterator iter = results.iterator();
            long ctr = -1, ctr2 = 0;

            while (iter.hasNext())
            {
                RdfBindingRow row = (RdfBindingRow)iter.next();

                // Since SPARQL processing may be lazy-delayed,
                // add any new comments that might have been logged.
                resultsink.AddComments(sourcewrapper.GetLog());

                ctr++;

                if (ctr < ReturnStart && ReturnStart != -1)
                {
                    continue;
                }

                for (int i = 0; i < bindings.Length; i++)
                {
                    Resource r = sourcewrapper.ToResource(row.getValue(svars[i]));
                    r           = sourcewrapper.Persist(r);
                    bindings[i] = new VariableBinding(bindings[i].Variable, r);
                }

                resultsink.AddComments(sourcewrapper.GetLog());

                resultsink.Add(bindings);

                ctr2++;
                if (ctr2 >= ReturnLimit && ReturnLimit != -1)
                {
                    break;
                }
            }

            resultsink.AddComments(sourcewrapper.GetLog());

            // Close the result sink.
            resultsink.Finished();
        }
예제 #4
0
        public override void Run(SelectableSource targetModel, QueryResultSink result)
        {
            CheckInit();

            foreach (Statement s in novariablestatements)
            {
                if (!targetModel.Contains(s))
                {
                    return;
                }
            }

            VariableBinding[] finalbindings = new VariableBinding[variables.Length];
            for (int i = 0; i < variables.Length; i++)
            {
                finalbindings[i].Variable = variableEntities[i];
            }

            result.Init(finalbindings, true, false);

            Debug("Begnning Query");

            BindingSet bindings = new BindingSet(this);

            for (int group = 0; group < statements.Length; group++)
            {
                bool ret = Query(group, bindings, targetModel);
                if (!ret)
                {
                    // A false return value indicates the query
                    // certainly failed -- a non-optional statement
                    // failed to match at all.
                    result.Finished();
                    return;
                }
            }

            int ctr = -1;

            foreach (QueryResult r in bindings.Results)
            {
                Permutation permutation = new Permutation(r.Bindings);
                do
                {
                    ctr++;
                    if (ctr < ReturnStart)
                    {
                        continue;
                    }
                    for (int i = 0; i < variables.Length; i++)
                    {
                        finalbindings[i].Target = permutation[i];
                    }
                    result.Add(finalbindings);
                    if (ReturnLimit != -1 && ctr == ReturnStart + ReturnLimit)
                    {
                        break;
                    }
                } while (permutation.Next());
                if (ReturnLimit != -1 && ctr == ReturnStart + ReturnLimit)
                {
                    break;
                }
            }


            result.Finished();
        }