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); }
public void AddNewRDFData(string rdfData, bool removeExistingDataForSubjects) { MemoryStore store = new MemoryStore(); RdfXmlReader reader = new RdfXmlReader(new System.IO.StringReader(rdfData)); store.Import(reader); // its possible that we want to update info about some existing concept // if removeExistingDataForSubjects is true we first remove existing information before we start adding statements if (removeExistingDataForSubjects) { foreach (Entity subject in store.SelectSubjects(null, null)) _conceptsStore.Remove(new Statement(subject, null, null)); } foreach (Statement s in store.Select(new Statement(null, null, null))) AddNewStatement(s); foreach (Entity subject in store.SelectSubjects(null, null)) UpdateSuggestionsForUri(subject.Uri); }
private void ReadGazetteerSettings(MemoryStore rdfStore, out CaseMatchingType caseMatchingType, out bool lemmatize, out bool enabled) { caseMatchingType = CaseMatchingType.IgnoreCase; lemmatize = false; enabled = true; ArrayList<string> crumbs = new ArrayList<string>(new string[] { mUri }); Entity[] objects = rdfStore.SelectSubjects(P_IDENTIFIED_BY, new Entity(mUri)); if (objects.Length > 0) { Resource[] objTypes = rdfStore.SelectObjects(objects[0].Uri, P_TYPE); if (objTypes.Length > 0) { crumbs.Add(objTypes[0].Uri); Resource[] superClass = rdfStore.SelectObjects((Entity)objTypes[0], P_SUBCLASS_OF); while (superClass.Length > 0) { crumbs.Add(superClass[0].Uri); superClass = rdfStore.SelectObjects((Entity)superClass[0], P_SUBCLASS_OF); } } } crumbs.Reverse(); foreach (string uri in crumbs) { Resource[] settings = rdfStore.SelectObjects(uri, P_SETTINGS); if (settings.Length == 0) { settings = rdfStore.SelectObjects(uri, P_COMMENT); } // for compatibility with OWL-DL if (settings.Length > 0) { string settingsStr = ((Literal)settings[0]).Value; ParseGazetteerSettings(settingsStr, ref caseMatchingType, ref lemmatize, ref enabled); } } }
public void ReadConditions(MemoryStore rdfStore, Dictionary<string, Gazetteer> gazetteers) { ArrayList<string> crumbs = new ArrayList<string>(new string[] { mUri }); Entity[] objects = rdfStore.SelectSubjects(P_IDENTIFIED_BY, new Entity(mUri)); if (objects.Length > 0) { Resource[] objTypes = rdfStore.SelectObjects(objects[0].Uri, P_TYPE); if (objTypes.Length > 0) { crumbs.Add(objTypes[0].Uri); Resource[] superClass = rdfStore.SelectObjects((Entity)objTypes[0], P_SUBCLASS_OF); while (superClass.Length > 0) { crumbs.Add(superClass[0].Uri); superClass = rdfStore.SelectObjects((Entity)superClass[0], P_SUBCLASS_OF); } } } crumbs.Reverse(); foreach (string uri in crumbs) { Resource[] conditionGazetteers = rdfStore.SelectObjects(uri, P_HAS_SENTENCE_LEVEL_CONDITION); foreach (Entity conditionGazetteer in conditionGazetteers) { mConditions.Add(new Condition(gazetteers[conditionGazetteer.Uri], Condition.Level.Sentence)); } conditionGazetteers = rdfStore.SelectObjects(uri, P_HAS_BLOCK_LEVEL_CONDITION); foreach (Entity conditionGazetteer in conditionGazetteers) { mConditions.Add(new Condition(gazetteers[conditionGazetteer.Uri], Condition.Level.Block)); } conditionGazetteers = rdfStore.SelectObjects(uri, P_HAS_DOCUMENT_LEVEL_CONDITION); foreach (Entity conditionGazetteer in conditionGazetteers) { mConditions.Add(new Condition(gazetteers[conditionGazetteer.Uri], Condition.Level.Document)); } } }