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); } }
public void InteropSemWebWriteVia() { Graph g = new Graph(); FileLoader.Load(g, "InferenceTest.ttl"); MemoryStore mem = new MemoryStore(); SemWebConverter.ToSemWeb(g, mem); RdfWriter writer = new RdfXmlWriter("semweb.rdf"); writer.Write(mem); writer.Close(); //Read the output graph back in to check for equality Graph h = new Graph(); FileLoader.Load(h, "semweb.rdf"); Assert.AreEqual(g, h, "Graphs should have been equal"); }
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); } }
static void Main(string[] args) { 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 rdfsReasoner = new RDFS(); rdfsReasoner.LoadSchema(rdfStore); rdfStore.AddReasoner(rdfsReasoner); /*using (var wr = new RdfXmlWriter(Console.Out)) { wr.BaseUri = NS.NrMeta; wr.Write(rdfStore); }*/ /*var r = rdfStore.Contains(new Statement( (Entity)(NS.NrDotNetType + "NReco.Operations.ChainOperationCall"), (Entity)NS.Rdfs.subClassOfEntity, (Entity)(NS.NrDotNetType + "NReco.Operations.OperationCall") )); // Console.WriteLine(r.ToString());*/ /*foreach (Statement s in rdfStore.Select(new Statement( (Entity)(NS.NrDotNetProp+"ContextFilter"), (Entity)NS.Rdfs.domainEntity, null))) { //Entity)(NS.NrDotNetType + "NReco.IProvider`2") Console.WriteLine(s.Object.Uri.ToString()); }*/ /*Query query = new GraphMatch(new N3Reader(new StringReader(rdfQuery))); QueryResultSink sink = new SparqlXmlQuerySink(Console.Out); query.Run(rdfStore, sink); */ using (RdfXmlWriter wr = new RdfXmlWriter(@"c:\temp\_1.rdf")) { //wr.BaseUri = NS.NrMeta; //wr.Namespaces.AddNamespace(NS.DotNet.Type, "t"); //wr.Namespaces.AddNamespace(NS.DotNet.Property, "p"); wr.Write(rdfStore); } Console.ReadKey(); }
public static void Main() { Store store = new MemoryStore(); store.Import(RdfReader.LoadFromUri(new Uri(example_foaf_file))); // Dump out the data, for fun using (RdfWriter writer = new RdfXmlWriter(Console.Out)) { writer.Write(store); } Console.WriteLine("These are the people in the file:"); foreach (Statement s in store.Select(new Statement(null, rdftype, foafPerson))) { foreach (Resource r in store.SelectObjects(s.Subject, foafname)) Console.WriteLine(r); } Console.WriteLine(); Console.WriteLine("And here's RDF/XML just for some of the file:"); using (RdfWriter w = new RdfXmlWriter(Console.Out)) { store.Select(new Statement(null, foafname, null), w); store.Select(new Statement(null, foafknows, null), w); } Console.WriteLine(); }
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(); }
/// <summary> /// new ontology concepts can be added while KEUI is running. we have to store the new data /// </summary> public void SaveAnnotationOntology(string fileName) { try { string RDFS = "http://www.w3.org/2000/01/rdf-schema#"; string RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; Entity rdfValue = RDF + "value"; Entity rdfsComment = RDFS + "comment"; // remove existing value properties _conceptsStore.Remove(new Statement(null, rdfValue, null)); // create new value properties with updated values foreach (Statement s in _conceptsStore.Select(new Statement(null, rdfsComment, null))) { int value = GetConceptFrequencyCount(s.Subject.Uri); if (value > 0) _conceptsStore.Add(new Statement(s.Subject.Uri, rdfValue, (Literal)value.ToString())); } string tempName = fileName + ".temp"; RdfXmlWriter.Options options = new RdfXmlWriter.Options(); options.EmbedNamedNodes = false; using (RdfWriter writer = new RdfXmlWriter(tempName, 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(_conceptsStore); } // if we successfully saved the ontology to the temp name only then rename the temp file to the correct name if (System.IO.File.Exists(fileName)) System.IO.File.Delete(fileName); System.IO.File.Move(tempName, fileName); } catch (Exception ex) { AddEvent("Exception while saving the annotation ontology. Error: " + ex.Message); GenLib.Log.LogService.LogException("Exception while saving the annotation ontology", ex); } }
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 ""; } }