Ejemplo n.º 1
0
        public void Run(IComponentsConfig config, string targetFile)
        {
            var rdfStore = new MemoryStore();

            rdfStore.Add(new Statement(NS.CSO.classEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity));
            rdfStore.Add(new Statement(NS.CSO.interfaceEntity, NS.Rdfs.subClassOf, NS.Rdfs.ClassEntity));

            var assemblyExtractor = new AssemblyMetadata();
            assemblyExtractor.Extract( System.Web.HttpRuntime.BinDirectory, rdfStore);

            var configExtractor = new WinterMetadata();
            var baseUri = String.IsNullOrEmpty(BaseUri) ?
                "file:///"+System.Web.HttpRuntime.AppDomainAppPath.Replace('\\','/')+"#" :
                BaseUri;
            configExtractor.BaseNs = baseUri;
            configExtractor.Extract(config, rdfStore);

            using (RdfXmlWriter wr = new RdfXmlWriter(targetFile)) {
                wr.BaseUri = NS.NrMeta;
                wr.Namespaces.AddNamespace(NS.DotNet.Type, "type");
                wr.Namespaces.AddNamespace(NS.DotNet.Property, "prop");
                wr.Namespaces.AddNamespace(NS.NrMetaTerms, "nr");
                wr.Write(rdfStore);
            }
        }
Ejemplo n.º 2
0
    public static void Main()
    {
        // Create the instance data

        MemoryStore dataModel = new MemoryStore();

        BNode me = new BNode("me");
        BNode you = new BNode("you");

        Entity rdfType = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
        Entity rdfsLabel= "http://www.w3.org/2000/01/rdf-schema#label";
        Entity foafPerson = "http://xmlns.com/foaf/0.1/Person";
        Entity foafAgent = "http://xmlns.com/foaf/0.1/Agent";
        Entity foafName = "http://xmlns.com/foaf/0.1/name";

        dataModel.Add(new Statement(me, rdfType, foafPerson));
        dataModel.Add(new Statement(you, rdfType, foafPerson));
        dataModel.Add(new Statement(me, foafName, (Literal)"John Doe"));
        dataModel.Add(new Statement(you, foafName, (Literal)"Sam Smith"));

        // Create the RDFS engine and apply it to the data model.

        RDFS engine = new RDFS();
        engine.LoadSchema(RdfReader.LoadFromUri(new Uri("http://xmlns.com/foaf/0.1/index.rdf")));

        dataModel.AddReasoner(engine);

        // Query the data model

        // Ask for who are typed as Agents.  Note that the people are
        // typed as foaf:Person, and the schema asserts that foaf:Person
        // is a subclass of foaf:Agent.
        Console.WriteLine("Who are Agents?");
        foreach (Entity r in dataModel.SelectSubjects(rdfType, foafAgent))
            Console.WriteLine("\t" + r);

        // Ask for the rdfs:labels of everyone.  Note that the data model
        // has foaf:names for the people, and the schema asserts that
        // foaf:name is a subproperty of rdfs:label.
        Console.WriteLine("People's labels:");
        foreach (Statement s in dataModel.Select(new Statement(null, rdfsLabel, null)))
            Console.WriteLine("\t" + s);
    }
Ejemplo n.º 3
0
    public static void Main()
    {
        MemoryStore store = new MemoryStore();

        Entity computer = new Entity("http://example.org/computer");
        Entity says = "http://example.org/says";
        Entity wants = "http://example.org/wants";
        Entity desire = new BNode();
        Entity description = new Entity("http://example.org/description");

        store.Add(new Statement(computer, says, (Literal)"Hello world!"));
        store.Add(new Statement(computer, wants, desire));
        store.Add(new Statement(desire, description, (Literal)"to be human"));
        store.Add(new Statement(desire, RDF+"type", (Entity)"http://example.org/Desire"));

        using (RdfWriter writer = new RdfXmlWriter(Console.Out)) {
            writer.Namespaces.AddNamespace("http://example.org/", "ex");
            writer.Write(store);
        }
    }
Ejemplo n.º 4
0
    public static void Main()
    {
        MemoryStore store = new MemoryStore();

        Entity container = new Entity("http://www.example.org/#container");

        store.Add(new Statement(container, RDF+"type", (Entity)(RDF+"Bag")));
        store.Add(new Statement(container, RDF+"_3", (Literal)"Three"));
        store.Add(new Statement(container, RDF+"_2", (Literal)"Two"));
        store.Add(new Statement(container, RDF+"_1", (Literal)"One"));

        // use the rdfs:member property to match for any rdf:_### predicates.
        Entity rdfs_member = (Entity)(RDFS+"member");

        using (RdfWriter writer = new N3Writer(Console.Out)) {
            writer.Namespaces.AddNamespace(RDF, "rdf");
            store.Select(new Statement(container, rdfs_member, null), writer);
        }

        foreach (Resource r in store.SelectObjects(container, rdfs_member))
            Console.WriteLine(r);
    }
 public static void Add(string s, string p, string o, MemoryStore ms)
 {
     if (!string.IsNullOrEmpty(s) && !string.IsNullOrEmpty(p) && !string.IsNullOrEmpty(o))
     {
         ms.Add(new Statement(new Entity(s), new Entity(p), new Literal(o), Statement.DefaultMeta));
         #region Tracing
     #line hidden
         if (Logger.IsDebugEnabled)
         {
             Logger.Debug("Added <{0}> <{1}> <{2}>.", s,p,o);
         }
     #line default
         #endregion
     }
 }
Ejemplo n.º 6
0
            public void Replace(Entity a, Entity b)
            {
                MemoryStore removals  = new MemoryStore();
                MemoryStore additions = new MemoryStore();

                foreach (Statement statement in statements)
                {
                    if ((statement.Subject != null && statement.Subject == a) || (statement.Predicate != null && statement.Predicate == a) || (statement.Object != null && statement.Object == a) || (statement.Meta != null && statement.Meta == a))
                    {
                        removals.Add(statement);
                        additions.Add(statement.Replace(a, b));
                    }
                }
                RemoveAll(removals.ToArray());
                Import(additions);
            }
Ejemplo n.º 7
0
        public virtual void Replace(Entity find, Entity replacement)
        {
            MemoryStore deletions = new MemoryStore();
            MemoryStore additions = new MemoryStore();

            Select(new Statement(find, null, null, null), deletions);
            Select(new Statement(null, find, null, null), deletions);
            Select(new Statement(null, null, find, null), deletions);
            Select(new Statement(null, null, null, find), deletions);

            foreach (Statement s in deletions)
            {
                Remove(s);
                additions.Add(s.Replace(find, replacement));
            }

            foreach (Statement s in additions)
            {
                Add(s);
            }
        }
Ejemplo n.º 8
0
    public static void Main()
    {
        // Create the instance data

        MemoryStore dataModel = new MemoryStore();

        BNode paris = new BNode("paris");
        BNode orleans = new BNode("orleans");
        BNode chartres = new BNode("chartres");
        BNode amiens = new BNode("amiens");
        BNode blois = new BNode("blois");
        BNode bourges = new BNode("bourges");
        BNode tours = new BNode("tours");
        BNode lemans = new BNode("lemans");
        BNode angers = new BNode("angers");
        BNode nantes = new BNode("nantes");

        Entity oneway = new Entity("http://www.agfa.com/w3c/euler/graph.axiom#oneway");
        Entity path = new Entity("http://www.agfa.com/w3c/euler/graph.axiom#path");

        dataModel.Add(new Statement(paris, oneway, orleans));
        dataModel.Add(new Statement(paris, oneway, chartres));
        dataModel.Add(new Statement(paris, oneway, amiens));
        dataModel.Add(new Statement(orleans, oneway, blois));
        dataModel.Add(new Statement(orleans, oneway, bourges));
        dataModel.Add(new Statement(blois, oneway, tours));
        dataModel.Add(new Statement(chartres, oneway, lemans));
        dataModel.Add(new Statement(lemans, oneway, angers));
        dataModel.Add(new Statement(lemans, oneway, tours));
        dataModel.Add(new Statement(angers, oneway, nantes));

        // Create the inference rules by reading them from a N3 string.

        string rules =
            "@prefix : <http://www.agfa.com/w3c/euler/graph.axiom#>.\n" +
            "\n" +
            "{ ?a :oneway ?b } => { ?a :path ?b } .\n" +
            "{ ?a :path ?b . ?b :path ?c . } => { ?a :path ?c } .\n";

        // Create our question in the form of a statement to test.

        Statement question = new Statement(paris, path, nantes);

        // Create the Euler engine

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

        // First Method of Inference:
        // Ask the engine whether there is a path from paris to nantes.
        // The Prove method will return a list of proofs, or an empty
        // array if it could not find a proof.

        foreach (Proof p in engine.Prove(dataModel, new Statement[] { question })) {
            Console.WriteLine(p.ToString());
        }

        // Second Method of Inference:
        // Apply the engine to the data model and then use the data
        // model's Contains method to see if the statement is "in"
        // the model + reasoning.

        dataModel.AddReasoner(engine);

        Console.WriteLine("Euler Says the Question is: " + dataModel.Contains(question));
    }
        private void ButtonGroupAdd_Click(object sender, EventArgs e)
        {
            if (ListViewCandidates.SelectedItems.Count < 2)
            {
                MessageBox.Show("To use the Group add functionality you have to select at least 2 candidates from the list");
                return;
            }

            Store tempStore = new MemoryStore();
            foreach (ListViewItem item in ListViewCandidates.SelectedItems)
            {
                string label = (item.Tag as Tuple<string, double>).Item1;
                string uri = GetSuggestedConceptUri(label);
                if (_ao.ConceptUriToDescription.ContainsKey(uri))
                {
                    MessageBox.Show("The concept with uri " + uri + " already exists. Ignoring it.");
                    continue;
                }
                if (_ao.ConceptLabelToUri.ContainsKey(label.ToLower()))
                {
                    MessageBox.Show("The label " + label + " is already assigned to concept " + _ao.ConceptLabelToUri[label.ToLower()] + ". Skipping the label.");
                    continue;
                }
                tempStore.Add(new Statement(new Entity(uri), AnnotationOntology.RelRdfsLabel, (Literal)label));
            }

            // remove the added items
            List<ListViewItem> selectedItems = new List<ListViewItem>(from ListViewItem item in ListViewCandidates.SelectedItems select item);
            foreach (var item in selectedItems)
                ListViewCandidates.Items.Remove(item);

            // send the statements as an event
            System.IO.StringWriter strWriter = new System.IO.StringWriter();
            RdfXmlWriter.Options options = new RdfXmlWriter.Options();
            options.EmbedNamedNodes = false;
            using (RdfWriter writer = new RdfXmlWriter(strWriter, options))
                writer.Write(tempStore);
            string newRDFData = strWriter.ToString();
            SendRDFData(newRDFData);
            _ao.AddNewRDFData(newRDFData, true);
        }
        private void ButtonAddSelectedConcept_Click(object sender, EventArgs e)
        {
            string candidate = TextBoxLabels.Text;
            Debug.Assert(!string.IsNullOrEmpty(candidate));

            if (string.IsNullOrEmpty(TextBoxConceptUri.Text))
            {
                MessageBox.Show("You have to specify a URI of the concept.");
                return;
            }

            if (_ao.ConceptUriToDescription.ContainsKey(TextBoxConceptUri.Text) && _editingExistingConcept == false)
            {
                MessageBox.Show("The concept with uri " + TextBoxConceptUri.Text + " already exists. Please specify a unique URI.");
                return;
            }

            // compute what are all the labels for the concept
            List<string> labels = candidate.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
            labels = (from label in labels select label.Trim()).ToList();

            if (labels.Count == 0)
            {
                MessageBox.Show("You have to specify at least one label for the concept.");
                return;
            }

            string uri = TextBoxConceptUri.Text;
            Entity concept = new Entity(uri);

            Store tempStore = new MemoryStore();
            foreach (string label in labels)
            {
                if (_ao.ConceptLabelToUri.ContainsKey(label.ToLower()) && _editingExistingConcept == false)
                {
                    MessageBox.Show("The label " + label + " is already assigned to concept " + _ao.ConceptLabelToUri[label.ToLower()] + ". Skipping the label.");
                    continue;
                }
                tempStore.Add(new Statement(concept, AnnotationOntology.RelRdfsLabel, (Literal)label));
            }

            if (!string.IsNullOrEmpty(TextBoxDescription.Text))
                tempStore.Add(new Statement(concept, AnnotationOntology.RelRdfsComment, (Literal)TextBoxDescription.Text));

            foreach (ListViewItem item in ListViewRelated.Items)
            {
                string conceptUri = (string)item.Tag;
                string relationStr = item.SubItems[2].Text;
                tempStore.Add(new Statement(concept, (Entity)_relationToUri[relationStr], new Entity(conceptUri)));
            }

            // send the statements as an event
            System.IO.StringWriter strWriter = new System.IO.StringWriter();
            RdfXmlWriter.Options options = new RdfXmlWriter.Options();
            options.EmbedNamedNodes = false;
            using (RdfWriter writer = new RdfXmlWriter(strWriter, options))
                writer.Write(tempStore);
            string newRDFData = strWriter.ToString();

            SendRDFData(newRDFData);
            _ao.AddNewRDFData(newRDFData, true);

            // remove the added items
            List<ListViewItem> selectedItems = new List<ListViewItem>(from ListViewItem item in ListViewCandidates.SelectedItems select item);
            foreach (var item in selectedItems)
                ListViewCandidates.Items.Remove(item);
            TextBoxLabels.Text = "";
            TextBoxConceptUri.Text = "";
            TextBoxDescription.Text = "";
            ListViewRelated.Items.Clear();
        }
        public string GetAnnotationOntologyRDF(bool includeComment, bool includeLinksTo)
        {
            try
            {
                Store smallStore = new MemoryStore();
                foreach (Statement s in _conceptsStore.Select(new Statement(null, null, null)))
                {
                    if (s.Predicate == RelRdfsComment && includeComment == false)
                        continue;
                    if (s.Predicate == RelDbAbstract && includeComment == false)
                        continue;
                    if (s.Predicate == RelLinksTo && includeLinksTo == false)
                        continue;
                    smallStore.Add(s);
                }

                System.IO.StringWriter strWriter = new System.IO.StringWriter();
                RdfXmlWriter.Options options = new RdfXmlWriter.Options();
                options.EmbedNamedNodes = false;
                using (RdfWriter writer = new RdfXmlWriter(strWriter, options))
                {
                    writer.Namespaces.AddNamespace("http://example.org/", "ex");
                    writer.Namespaces.AddNamespace("http://www.w3.org/2002/27/owl#", "owl");
                    writer.Namespaces.AddNamespace("http://dbpedia.org/ontology/", "DBpedia");
                    writer.Namespaces.AddNamespace("http://ailab.ijs.si/alert/predicate/", "ailab");
                    writer.Namespaces.AddNamespace("http://purl.org/dc/terms/", "purl");
                    writer.Namespaces.AddNamespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
                    writer.Namespaces.AddNamespace("http://www.w3.org/2000/01/rdf-schema#", "rdfs");

                    writer.Write(smallStore);
                }
                return strWriter.ToString();
            }
            catch (Exception ex)
            {
                AddEvent("Exception while sending the annotation ontology as string. Error: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while sending the annotation ontology as string", ex);
                return "";
            }
        }
Ejemplo n.º 12
0
		public virtual void Replace(Entity find, Entity replacement) {
			MemoryStore deletions = new MemoryStore();
			MemoryStore additions = new MemoryStore();
			
			Select(new Statement(find, null, null, null), deletions);
			Select(new Statement(null, find, null, null), deletions);
			Select(new Statement(null, null, find, null), deletions);
			Select(new Statement(null, null, null, find), deletions);
			
			foreach (Statement s in deletions) {
				Remove(s);
				additions.Add(s.Replace(find, replacement));
			}
			
			foreach (Statement s in additions) {
				Add(s);
			}
		}
Ejemplo n.º 13
0
		public override void Replace(Entity a, Entity b) {
			MemoryStore removals = new MemoryStore();
			MemoryStore additions = new MemoryStore();
			foreach (Statement statement in statements) {
				if ((statement.Subject != null && statement.Subject == a) || (statement.Predicate != null && statement.Predicate == a) || (statement.Object != null && statement.Object == a) || (statement.Meta != null && statement.Meta == a)) {
					removals.Add(statement);
					additions.Add(statement.Replace(a, b));
				}
			}
			RemoveAll(removals.ToArray());
			Import(additions);
		}