SPARQL-queries (HELP!) - ontology

So, I have an Ontology and need some help with my SPARQL-queries.
The ontology is based on different beer ingredients and equipment for brewing.
For instance, it has the class "Ingredients", and a subclass "Malt/Grain", and then a subclass "Dark". Now I have some different, more specific types of dark malts, that are individuals, and members of the class Dark.
If I go into one individual in Protege, for instance "Dark_Crystal", will have "Dark" under its field of "Types"
So, I want to be able to ask queries like: "Show me all dark malts" "Show me the malt "Dark_Crystal", and if not in stock show alternative malts of the same type.
I´m not too good with SPARQL as much time have gone un to the ontology. I know a little, but I just don´t know how I would formulate it, or which tags that should define them.
This is my poor shot at a query, I just don´t know how i would formulate it right.
SELECT ?Malt WHERE
{
?malt rdfs:subClassOf [
owl:someValuesFrom :Dark
}
Thanks a lot guys, hope I explained it well enough and that some of you may have some examples.

I can't test because I do not have your ontology but on the top of my head, that's how I would do it:
If Dark is a literal:
SELECT ?malt WHERE
{
?malt :hasColor "Dark"
}
If Dark is a class:
SELECT ?malt WHERE
{
?malt :hasColor ?color.
?color rdf:type :Dark
}

Related

Cytoscape Passthrough mapping

I have a question regarding passthrough mapping on Cytoscape.
Let us say I have my nodes that belong to discreet groups. Those groups appear on a different column that I call Cat. How can I make the node fill colour to be according to Cat? I know I can do it with discrete mapping, choosing the Cat colours individually, but what if I have loads of Cats? When I choose Passthrough mappping, which I do not know how it works, nothing happens.
Thanks for your help.
Best,
David R.
Passthrough mapping does sort of what it sounds like -- it maps the value in the column cell to the visual attribute. In this case, you are mapping whatever is in Cats to a Color. Now, if you have a value of "Group 1", and Cytoscape maps it to a color, you wind up with ... nothing since Cytoscape doesn't know how to do that mapping. My suggestion would be to use discrete mapping, but let Cytoscape choose the colors. If you right-click on the "Discrete Mapping" and then go to "Mapping Value Generators" you'll see a number of options for automatically assigning colors.
-- scooter

Expressing, querying and enforcing constraints on graph contents

Say you would like to create a graph authoring system that puts constraints on the contents of the graph. Say you have a "contains" relationship where "city" may contain "houses", which in turn contain "bedrooms" and "bathrooms". But it is not legal for a city to contain bedrooms or bathrooms, or for bathrooms to contain bedrooms.
Further, say you want to offer suggestions to graph author - if they select a "city" node, you might want to give them suggestions for what can be added to the city "houses", "hospitals" and "schools", but not "bedrooms".
I am guessing that these constraints, in and of themselves, could be represented as a graph. Has anyone had any luck doing that? What was your experience?
There are a number of ways you could express these rules, for example:
You could use your application layer to check whether Node Label to Relationship Type rules are being respected
You could perhaps use triggers to check/act on any specific rules
You may choose to create user defined rules engine
There will be other approaches too.

Neo4j/Cypher Query (user action) relationship direction

I am new to Cypher and trying to design a graphic database and store user behaviour. Thanks in advance!
Case Example:
1. A user visited a web page
2. A user owned a device (id:xxxxx)
In UML Class diagram, the arrow (relationship) is pointing toward to parent class
But, my point of view, not all relationship in Cypher are Parent-Child type, does it means that i should not apply this kind of concept into Cypher?
So, the question is "how to design the direction of relationship"?
(user)-[r:visited]->(webpage {url:xxx})
(user)-[r:owned]->(mobileDevice {uuid:xxx})
-- or --
(user)<-[r:visitedBy]-(webpage {url:xxx})
(user)<-[r:owned]-(mobileDevice {uuid:xxx})
Thank you again
This is a common question. The answer is that it's up to you! Relationship types can be whatever you choose and you should go with what is most comfortable. I would suggest that whatever you do, just try to be consistent.
Personally between "visted" and "visited by", I would go with "visited" because I think it makes more sense to be talking about the fact that the user visited a page, not that a page was visited by the user. I often recommend that people name their relationships so that the node-relationship-node makes a sentence. Since the user is the primary actor your sentence would be "(the) user visited (the) webpage". That might come from me being a native English speaker and the way that English sentences are formed, though.
As a side note, relationships in Neo4j are generally UPPER_SNAKE_CASE. Again, Neo4j doesn't restrict you from any one particular style, but that's what I've seen most. This guide gives a pretty good overview of common Cypher conventions:
http://nigelsmall.com/zen

Protege Ontology Help Sub class, Sibling Class

quick question ive got a couple of sibling classes which include sub classes now what i want to do is connect a sub classes to two diffrent sibling classes, is this possible? also i want it to show in the owlviz.
example
sibling class:
rules
goals
sub class:
collect
so i want sub class collect to feature or be connected in both of the sibling classes. as the software does let me type the same name in each sibling class.
thanks
I don't quite understand the question. You can just assert the fact that collect is a subclass of both rules and goals straight from the Protege User Interface.
Make sure all of your classes are present in your isA hierarchy
Select the class collect
In Protege 4, click on the little "+" icon next to the "Superclasses" section in the Class Description Window
Assert "rules" as a superclass
Repeat and assert "goals" as a superclass.
Now "collect is a subclass of both "rules" and "goals".
AS an aside, it is not normally considered good practice to have multiple asserted inheritance in ontologies. For large ontologies, this can become a maintenance nightmare. If all you need is a small practical solution to a problem, then ok.
The visualisation of your ontology can also be done Protege - you need Graphviz installed first and point Protege to the location of the graphviz executable on your system.
Hope this helps!

How to sort websites into categories based on keyword content

I'm writing a webrobot which categorizes sites based on there keyword/meta/links into a predefined list of categories.
I've been looking at various ontology approaches and have looked at Wordnet (for the hypernym/hyponym), ResearchCyc , WebKb and was wondering if this was as hard a problem as I'm thinking or has it been solved somewhere else before.
Essentially I have large stacks of sorted keyword values and would like to use them to match against a category name. My current thoughts are to check against the category name in some kind of ontology hierarchy.
Has anyone else approached a ontology based problem like this?
Cheers!
You might want to look at text mining, specifically keyword mining or subject indexing, research.

Resources