Checking Ontology Consistency in Run Time - protege

I have a program that uses Jena to load an .owl Ontology designed in Protege. I am trying to do reasoning over it using Pellet in a way that if I add some statements in run time to model be able to check its consistency. For example I have 'Method', 'Signature' and 'hasSignature' concepts in which hasSignature is an object property. I have following axiom:
Method hasSignature exactly 1 Signature
When I add some instance statements in order to violate above axiom no inconsistency is reported. Here is my code:
List<Statement> statements = new ArrayList<>();
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF);
FileManager.get().readModel(model, "Ontologies\\Ontology.owl");
OntClass Method = model.createClass( ns + "Method");
Individual method1 = Method.createIndividual(ns + "method1");
OntClass Signature = model.createClass( ns + "Signature");
Individual sign1 = Signature.createIndividual(ns + "sign1");
Individual sign2 = Signature.createIndividual(ns + "sign2");
Property hasSignature = model.createObjectProperty(ns + "hasSignature");
Statement st = model.createStatement(method1, hasSignature, sign1);
statements.add(st);
Statement st1 = model.createStatement(method1, hasSignature, sign2);
statements.add(st1);
Reasoner reasoner = PelletReasonerFactory.theInstance().create();
InfModel inf = ModelFactory.createInfModel(reasoner, model.add(statements));
System.out.println(inf.validate().isValid());
What's wrong? Why it doesn't work?

You have not declared sign1 and sign2 to be different from each other. So, since it is possible for the two individuals to be sameAs each other, the reasoner has determined that that's the only case not rising a clash. Therefore the ontology is consistent.

Related

How to set compound structure for two different layers if I used 2 different categories of material for wall structure , using revit api

I am trying to create a wall with 2 layers and each layer materials are different. When I try to set the CompoundStructure for the wall I am getting an exception that CompoundStructure is not valid.
CompoundStructure cStructure = CompoundStructure.CreateSimpleCompoundStructure(clayer);
wallType.SetCompoundStructure(cStructure);
Can anyone tell me how I can create compound structure for layers with different materials?
First of all, solve your task manually through the end user interface and verify that it works at all.
Then, use RevitLookup and other database exploration tools to examine the results in the BIM elements, their properties and relationships.
Once you have done that, you will have a good idea how to address the task programmatically – and have confidence that it will work as expected:
How to research to find a Revit API solution
Intimate Revit database exploration with the Python Shell
newWallMaterial = wallMaterial.Duplicate("newCreatedMaterial");
newWallmaterial2 = wallMaterial.Duplicate("NewCreatedMAterial2");
//roofMaterial3 = roofMaterial2.Duplicate("NewCreatedMAterial3");
bool usr = newWallMaterial.UseRenderAppearanceForShading;
//newWallMaterial.Color = BuiltInTypeParam.materialCol;
foreach (Layers layer in layers)
{
if (layer.layerId == 0)
{
c = new CompoundStructureLayer(layer.width, layer.materialAssignement, newWallMaterial.Id);
newWallMaterial.Color = color;
clayer.Add(c);
}
if (layer.layerId == 1)
{
c1 = new CompoundStructureLayer(layer.width, layer.materialAssignement, newWallmaterial2.Id);
newWallmaterial2.Color = color;
clayer.Add(c1);
}

Drools update nested member attribute

I'm facing a problem while using Drools.
I try to update an attribute from a nested member. The update seems to work, but the when clause do not consider it.
I have 2 Obj object, sharing the same Cpt object.
Cpt cpt = new Cpt();
Obj obj1 = new Obj("obj1");
obj1.setComposant("R2");
obj1.counter = cpt;
Obj obj2 = new Obj("obj2");
obj2.setComposant("R2");
obj2.counter = cpt;
kSession.insert(obj2);
kSession.insert(obj1);
My rule is define as:
rule "R2"
when
m : Obj(composant == "R2" && counter.value == 0)
then
System.out.println(m.getName() + " " + m.getCounter().getValue());
m.getCounter().increment();
end
I was expecting Obj1 to match the when clause, then update the value of the counter (from 0 to 1). So the Obj2 should not match the where clause.
But in fact, it does, even if the display is as I expected :
obj1 0
obj2 1
Can someone explain me what am I doing wrong ?
All reactions of the Drools Rule Engine with respect to changes in the set of facts require to be notified by using one of the extensions for the Right Hand Side language. You need to call update(f) for the modified fact object f, or you may use the modify(f){...} statement.
However... Changing a contained object X via the reference from fact A and telling the Engine that fact A has been modified will not make it see that fact B, also referencing X, has been changed as well.
This is where you should reconsider your design. Is it really necessary to have an X shared via references from A and B? Or: what about making X a fact and updating it? The latter may mean that you have to rewrite your rules, making the relation between Obj and Cpt visible on the left hand side. But, in my experience, it is usually better to have this than some complex mechanism propagating update notifications from some joint contained object to its parents.
Edit What I mean by "making the relation visible" is shown by the rule below:
rule "R2"
when
Obj(composant == "R2", $counter: counter )
$c: Cpt( this == $counter, value == 0)
then
modify( $c ){ increment() }
end

How can I use Distinct on a group of bags in pig

This is my input as described below:
({(Fish M.),(Fish M.),(Fish M.),(Fish M.),(Fish M.)},{(Acasuso J.),(Acasuso J.),(Acasuso J.),(Acasuso J.),(Acasuso J.)},{(8/23/2007),(8/23/2007),(8/23/2007),(8/23/2007),(8/23/2007)},{(99.84002222685783),(58.173357215875676),(PSL),(41.66666501098216),(EXW)})
I would like to do a distinct on the first and second bags to get one result each to produce an output like this:
(Fish M., Acasuso J., 8/23/2007, 99.84002222685783, 58.173357215875676, PSL, 41.66666501098216, EXW)
This script should work, I have ignored the last bag in your entry for brevity.
rr = load 'data/pig/input/Pig_DataSets/six' using CustomLoadFunction() as (one:bag{tup1:(c1:chararray)},two:bag{tup2:(c2:chararray)},three:bag{tup3:(c3:chararray)});
tt = foreach rr {
mm = two;
nn = distinct mm;
oo = one;
pp = distinct oo;
generate three,pp,nn;
};
You might have to use a custom load function because the the default loader wont work (unless you do some data cleansing). This post talks about a custom loader that might fit your scenario.

Lua weak references

I'm working on a project in Lua where I will be creating tables and storing them in a master table, to be erased at a later time. I will pass around references to these tables to other sibling tables.
master = {}
table.insert(master, {name = 'hello'})
table.insert(master, {name = 'world', pre = master[1]})
The problem that occurs is that when I wish to erase the reference from the master table, the reference still remains in master[2] here. Obviously my first solution was to make the tables have weak values. (through .__mode on a metatable, not shown here)
This worked, and would work, so long as I would never store a singly-referenced table within these tables.
table.insert(master, {name = 'goodbye', pre = master[2], some_table = {123}})
The third element, some_table would eventually be collected, because the tables have weak values, and this table (some_table) is not referenced anywhere else. This is undesired behavior. My latest solution involves creating "weak reference objects" to the tables within the master table. A naive implementation follows:
function WeakRef(t)
r = {__mode = 'v', __index = t, __newindex = t}
setmetatable(r, r)
return r
end
These weak reference objects act similarly to boost::weak_ptrs and accomplish my goal, but I am uncertain if they are the best solution to my problem.
Is there a better way; a more elegant solution?
Is my design, which requires this master table, perhaps flawed?
Given that:
You want master to be the "one place" where you define whether an object exists or not
Your objects can have links between them
Then probably the simplest architecture is reserving one of the members of each object as a "middle man" in charge of managing the references to others. Here're the steps:
Make master a regular table (not weak)
On each physical object, create a weak table called links (or whatever name suits your logic better)
Make all links tables weak. Use them to store references to other objects.
And this is a possible implementation. I've tried it in Lua 5.1:
local function newWeakTable()
return setmetatable({}, {__mode = "v"})
end
local master = {}
-- create two physical objects
local obj1 = { name = "obj1", links = newWeakTable() }
local obj2 = { name = "obj2", links = newWeakTable() }
-- link them
obj2.links.pre = obj1
-- insert them into master
table.insert(master, obj1)
table.insert(master, obj2)
-- master has 2 objects, and they are linked
assert(#master == 2)
assert(obj2.links.pre == obj1)
-- remove obj1 from master, and remove the variable reference
table.remove(master, 1)
obj1 = nil
-- run gc manually
collectgarbage("collect")
-- master has only 1 object now, and the link has dissapeared
assert(#master == 1)
assert(obj2.links.pre == nil)
print("Everything went as expected")

Re-use of database object in sub-sonic

Yet another newbie SubSonic/ActiveRecord question. Suppose I want to insert a couple of records, currently I'm doing this:
using (var scope = new System.Transactions.TransactionScope())
{
// Insert company
company c = new company();
c.name = "ACME";
c.Save();
// Insert some options
company_option o = new company_option();
o.name = "ColorScheme";
o.value = "Red";
o.company_id = c.company_id;
o.Save();
o = new company_option();
o.name = "PreferredMode";
o.value = "Fast";
o.company_id = c.company_id;
o.Save();
scope.Complete();
}
Stepping through this code however, each of the company/company_option constructors go off and create a new myappDB object which just seems wasteful.
Is this the recommended approach or should I be trying to re-use a single DB object - and if so, what's the easiest way to do this?
I believe you can use the same object if you want to by setting its IsNew property to true, then change its data properties, save it again, repeat. Easy enough.
I 'm not so sure that you should bother, though. It depends on how bad those constructors are hurting you.
In my eyes assigning multiple objects to a single var is never a good idea but thats arguable. I would do this:
// Insert some options
company_option o1 = new company_option();
o1.name = "ColorScheme";
o1.value = "Red";
o1.company_id = c.company_id;
o1.Save();
company_option o2 = new company_option();
o2.name = "PreferredMode";
o2.value = "Fast";
o2.company_id = c.company_id;
o2.Save();
I you are worried about performance, that shouldn't be a issue unless you want to insert or update many objects at once. And again, in this case the time used for inserting the data takes longer than for the object creation.
If you are worried about performance you can skip the object creation and saving part completly by using a Insert query:
http://www.subsonicproject.com/docs/Linq_Inserts
db.Insert.Into<company_option>(
x => x.name,
x => x.value,
x => x.company_id)
.Values(
"ColorScheme",
"Red",
c.company_id
).Execute();

Resources