예제 #1
0
    protected override void OnLoad(EventArgs e)
    {
        RdfStore = new MemoryStore();
        RdfStore.Import(
            new RdfXmlReader(@"c:\temp\_1.rdf"));

        string depRules = @"
@prefix n: <urn:schemas-nreco:metadata:terms#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.

{ ?a n:dependentFrom ?b . ?b n:dependentFrom ?c .} => {?a n:dependentFrom ?c}.
{ ?a n:dependentFrom ?b } => { ?b n:usedBy ?a}.
{ ?a n:usedBy ?b . ?b n:usedBy ?c .} => {?a n:usedBy ?c}.
";

        Euler engine = new Euler(new N3Reader(new StringReader(depRules)));

        RdfStore.AddReasoner(new RDFS(RdfStore));
        RdfStore.AddReasoner(engine);

        string rdfQuery = @"
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix p: <urn:schemas-nreco:metadata:dotnet:property#>.
@prefix t: <urn:schemas-nreco:metadata:dotnet:type#>.
@prefix w: <file:///d:/Vitalik/GoogleCode/NReco/examples/NReco.Examples.WebApp/web/#>.
@prefix cso: <http://cos.ontoware.org/cso#>.
@prefix n: <urn:schemas-nreco:metadata:terms#>.
w:db n:usedBy ?t2.
";

        Query           query = new GraphMatch(new N3Reader(new StringReader(rdfQuery)));
        StringWriter    wr    = new StringWriter();
        QueryResultSink sink  = new SparqlXmlQuerySink(wr);

        query.Run(RdfStore, sink);
        Result = wr.ToString();

        base.OnLoad(e);
    }
예제 #2
0
        public static void MakeLean(Store store, SelectableSource relativeTo, StatementSink removed)
        {
            // Break the data source into MSGs.  Make each MSG
            // lean first (in isolation).  Then check each lean MSG
            // to see if it's already entailed by the whole store,
            // or by relativeTo if it's provided (not null).

            MSG.Graph[] msgs = MSG.FindMSGs(store, true);

            foreach (MSG.Graph msgg in msgs)
            {
                // Load the MSG into memory.
                MemoryStore msg = new MemoryStore(msgg);                 // unnecessary duplication...

                // Make this MSG lean.  The "right" thing to do is
                // to consider all of the 'connected' subgraphs of MSG
                // against the whole store, rather than the MSG in
                // isolation.  But that gets much too expensive.
                MemoryStore msgremoved = new MemoryStore();
                MakeLeanMSG(msg, msgg.GetBNodes(), msgremoved);

                // Whatever was removed from msg, remove it from the main graph.
                store.RemoveAll(msgremoved.ToArray());

                // And track what was removed.
                if (removed != null)
                {
                    msgremoved.Select(removed);
                }

                // If this MSG is now (somehow) empty (shouldn't happen,
                // but one never knows), don't test for entailment.
                if (msg.StatementCount == 0)
                {
                    continue;
                }

                // Remove this MSG if it is already entailed.

                // The GraphMatch will treat all blank nodes in
                // msg as variables.
                GraphMatch            match = new GraphMatch(msg);
                QueryResultBufferSink sink  = new QueryResultBufferSink();
                match.Run(new SubtractionSource(store, msg), sink);
                if (sink.Bindings.Count > 0)
                {
                    // This MSG can be removed.
                    store.RemoveAll(msg.ToArray());
                    if (removed != null)
                    {
                        msg.Select(removed);
                    }
                }
                else if (relativeTo != null)
                {
                    match.Run(relativeTo, sink);
                    if (sink.Bindings.Count > 0)
                    {
                        // This MSG can be removed.
                        store.RemoveAll(msg.ToArray());
                        if (removed != null)
                        {
                            msg.Select(removed);
                        }
                    }
                }
            }
        }