I have created an ontology using protege. Now I want to write a code to traverse ontology using dotNetRDF. By mean of traverse is displaying all classes, sub-classes etc.
I am using following code but it is giving exception **
The Namespace URI for the given Prefix 'owl' is not known by the
in-scope NamespaceMapper
OntologyGraph g = new OntologyGraph();
FileLoader.Load(g, "humanontordf.owl");
OntologyClass classOfClasses = g.CreateOntologyClass(g.CreateUriNode("owl:Class"));
//This iterates over the things that are a class
foreach (OntologyResource r in classOfClasses.Instances)
{
//Do what you want with the class
Console.WriteLine(r.ToString());
}
This code is base on answer given here (http://answers.semanticweb.com/questions/19984/dotnetrdf-list-all-ontology-classes)
Can anyone let me know what am I missing in above code? any good URL for tutorial on dotNetRDF?
The error message refers to the following part of your code:
g.CreateUriNode("owl:Class")
This uses a prefixed name as a shortcut for the full URI which requires the owl prefix to be defined in your graph.
If you are getting this then your RDF file does not include this, you can define this like so:
g.NamespaceMap.AddNamespace("prefix", new Uri("http://some/namespace/"));
I guess an OntologyGraph should really define the OWL namespace automatically, I'll add this in the next release.
Related
I have an ontology that contains two classes (course,lesson) the course has a data properties called code of type string
How to get all individuals from specific class with specific data properties value
here is a screenshot
The general pattern is something like this:
SELECT ?individual
WHERE { ?individual a <uri-of-specific-class> ;
<uri-of-property> ?propertyValue .
FILTER(STR(?propertyValue) = "expected value")
}
You will need to adapt this with the details of your specific ontology (the URIs of your class names and properties), but it shows the general approach. I would also suggest that you try out a SPARQL tutorial, there's several good ones online for you to find.
I have an input xml and it has only one Telephone child element,
<ContactMethod>
<Telephone type="fax">
<Number>String</Number>
<Extension>String</Extension>
</Telephone>
</ContactMethod>
But my output XML has multiple Telephone child element,
<ContactMethod>
<Telephone type="fax">
<Number>String</Number>
<Extension>String</Extension>
</Telephone>
<Telephone type="fax">
<Number>String</Number>
<Extension>String</Extension>
</Telephone>
</ContactMethod>
I want to map from input element Number to output Number and also Extension element.
I can't change the schema because it is globally used.
I don't see any options to map using Element Mapping.
And I tried using adding Rule to the ContactMethod element, but no luck.
......
Above I is just example I asked. I need one to many mapping idea in datamapper.
See attached image, that is my actual requirement. Look at the Disclosure/CandidateDisclosure elements in source and destination
My source is XML and target is JSON, but the actual logic I need is similar for all the structures ..
I am maintaining a project which use DataMapper and faced the same issue. To solve it I add Java Transformer (you can use Groovy or other scripting languages) after DataMapper to group the one-to-many relationship.
Following is the pseudo code:
provide empty telpMap
foreach telpXml which is extracted from src/payload {
key = telpXml.get("#type");
if (telpMap.containsKey(key)) {
List number = telpMap.get(key).get("Number");
number.addAll(telpXml.get("Number"));
List extension = telpMap.get(key).get("Extension");
extension.addAll(telpXml.get("Extension"));
} else {
telpMap.put(key, telpXml);
}
}
return telpMap.values();
I am a new to using Mongo DB and exploring the frameworks around for migrating from mysql to mongodb. So far from my findings I have been able to figure out SpringMongo as the best solution to my requirements.
The only problem is that instead of using a DSL based or abstract querying mechanism, I wished the framework allowed me to pass plain json string as arguments to the different methods exposed by the API(find, findOne) so that the query parameters can be written out to an external file (using a key to refer) and passed to the methods by reading and parsing at run time. But the framework should be capable of mapping the results to the domain objects.
Is there a way in spring-mongo to achieve this? Or is there any other frameworks on the same lines
You could use Spring Data to do that, just use the BasicQuery class instead of Query class. Your code will look like the following:
/* Any arbitrary string that could to parsed to DBObject */
Query q = new BasicQuery("{ filter : true }");
List<Entity> entities = this.template.find(q, Entity.class);
If you want more details:
http://static.springsource.org/spring-data/data-mongo/docs/current/reference/html/#mongo.query
http://static.springsource.org/spring-data/data-mongodb/docs/current/api/org/springframework/data/mongodb/core/query/BasicQuery.html
Well I got to find this one in the Spring data MongoOperations...
String jsonCommand = "{username: 'mickey'}";
MongoOperations mongoOps = //get mongooperations implemantation
mongoOps.executeCommand(jsonCommand)
It returns an instance of CommandResult that encapsulates the result.
I have ontology file which i have created using Protege.. For my java application i need to retrieve classes and their properties.. I have tried following code but it retrieves only tripples.. I m new to Jena Api and Ontology so pls help
String URI = "http://www.semanticweb.org/ontologies/2012/0/SBIRS.owl";
String inputFileName = "D:\\SBIRS.owl";
System.out.println("File Name" + inputFileName);
OntModel model = ModelFactory.createOntologyModel();
StmtIterator si=model.listStatements();
ResIterator iter=model.listSubjects();
while(iter.hasNext())
{
Resource res=iter.nextResource();
System.out.println("Property==>" + res.getProperty(null).toString());
System.out.println("Resource URI==>" + res.getURI());
}
To list the classes in an OntModel, use the listClasses method. Each returned result from that method will be an instance of the Java class OntClass, which provides convenient access to the triples from the underlying model which define the class.
When you say you need to retrieve "classes and their properties", you could mean two things: the RDF properties of the RDF resource that denotes the class, or the properties which are typically used with instances of the class. In the first case, you can get these through the API on OntClass (and its Java super-classes, e.g. Resource). In the second case, you need to read this how-to.
I am going through the RavenDB tutorial on the RavenDb.net website.
It was going fine until I got to the code block for creating an index.
This code segment is direct from RavenDB.Net website.
store.DatabaseCommands.PutIndex("OrdersContainingProduct", new IndexDefinition<Order>
{
Map = orders => from order in orders
from line in order.OrderLines
select new { line.ProductId }
});
I get an error on compile: "The non-generic type 'Raven.Database.Indexing.IndexDefinition' cannot be used with type arguments."
If IndexDefinition is non-generic, why is it used as generic in the sample code? Where is the disconnect?
Thank you for your time
Jim
Depending on your using statements you may be referencing the wrong IndexDefinition class (from another Raven assembly). Try adding this to the beginning of your file:
using Raven.Client.Indexes;
You might need to remove other using statements as well. I guess this is one reason why Microsoft recommends using unique names for classes even in the presence of namespaces.