-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial Creating a Bench
In this tutorial we will be creating a bench.
(!) This tutorial was based on an earlier version of the api, use it as a inspirational guide

Creating a Coins Container file (.ccr) typically consists of the following steps:
- Start a project in a DotNET or Java IDE.
- Instantiate a CoinsContainer instance.
- Interact with the CoinsContainer with the use of some interaction classes.
- Optionally trigger some post-processing.
- Export the CoinsContainer to a file.
-
For C#, open the File / New Project / Classic Desktop / Empty Project.
-
Add the following references Project / Add References:

-
Optionally, configure the logger (e.g. with this log4j.xml)
using org.apache.log4j.xml;
...
static void initLog()
{
DOMConfigurator.configure(@"c:\log4j.xml");
}Creating one element inside a new container and setting one property.
// Start container
CoinsGraphSet graphSet = new InMemGraphSet("http://coins.bedrijf.com#");
// Create the container content
JenaCoinsContainer ccr = new JenaCoinsContainer(graphSet, false, true);
// Create individual
RuntimeCoinsObject bench = new RuntimeCoinsObject(ccr, "http://www.coinsweb.nl/cbim-2.0.rdf#Object", "http://demo.nl#Object_Zitbank");
// Set property
bench.setLiteralValue("http://demo.nl#hasName", "Zitbank");
// Export container
ccr.export("C:\\bench_tutorial\\bench.zip");The resulting container file contains some folders and files:

The bim\content.rdf file has the following content:
<rdf:RDF
xmlns="http://demo.nl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:coins2="http://www.coinsweb.nl/cbim-2.0.rdf#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://demo.nl#">
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.coinsweb.nl/coins2/referencemodel/BranchVersioning#"/>
<owl:imports rdf:resource="http://www.coinsweb.nl/COINSWOA.rdf#"/>
<owl:imports rdf:resource="http://www.coinsweb.nl/units-2.0.rdf#"/>
<owl:imports rdf:resource="http://www.coinsweb.nl/cbim-2.0.rdf#"/>
<coins2:containerId rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>9d4e126c-834c-41b4-a898-93082043729b</coins2:containerId>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
</owl:Ontology>
<coins2:Object rdf:about="#3952ce87-a6a1-43ac-ad8e-061186192538">
<coins2:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>Zitbank</coins2:name>
<coins2:creationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>2016-05-03T12:06:43.791Z</coins2:creationDate>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
</coins2:Object>
</rdf:RDF>Above, only code from the coins-api.dll was used. This is very generic. To make life easier the generated libraries can be used. For example the cbim.dll contains code for all elements from the core model, like the Assembly or Object.
// Start container
CoinsGraphSet graphSet = new InMemGraphSet("http://coins.bedrijf.com#");
// Create the container content
JenaCoinsContainer ccr = new JenaCoinsContainer(graphSet, false, true);
// Create individual
Object bench = new Object(ccr);
// Set property
bench.setName("Zitbank");
// Export container
ccr.export("C:\\bench_tutorial\\bench.zip");The result is precisely as above, but now less code was needed.
The next step is a more complex property.
// Start container
CoinsGraphSet graphSet = new InMemGraphSet("http://coins.bedrijf.com#");
// Create the container content
JenaCoinsContainer ccr = new JenaCoinsContainer(graphSet, false, true);
// Property with a float value
Object kolom = new Object(ccr);
FloatProperty property = new FloatProperty(ccr);
property.setSimpleProperty(10.0f);
property.setUnit(LengthUnit.METER);
kolom.addHasProperties(property);
// Export container
ccr.export("C:\\bench_tutorial\\bench.zip");The content is of the content.rdf is:
<rdf:RDF
xmlns="http://demo.nl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:coins2="http://www.coinsweb.nl/cbim-2.0.rdf#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://demo.nl#">
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.coinsweb.nl/coins2/referencemodel/BranchVersioning#"/>
<owl:imports rdf:resource="http://www.coinsweb.nl/COINSWOA.rdf#"/>
<owl:imports rdf:resource="http://www.coinsweb.nl/units-2.0.rdf#"/>
<owl:imports rdf:resource="http://www.coinsweb.nl/cbim-2.0.rdf#"/>
<coins2:containerId rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>369458cb-17cf-4c1c-9a5e-3b57437b1361</coins2:containerId>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
</owl:Ontology>
<coins2:Object rdf:ID="a1414e34-815a-4b29-a36b-2421383c5427">
<coins2:hasProperties>
<coins2:FloatProperty rdf:about="#83d9a01a-4dc7-4364-8f7d-c185f2edaa96">
<coins2:unit rdf:resource="http://qudt.org/vocab/unit#Meter"/>
<coins2:datatypeValue rdf:datatype="http://www.w3.org/2001/XMLSchema#float"
>10.0</coins2:datatypeValue>
<coins2:creationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>2016-05-03T12:27:15.423Z</coins2:creationDate>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
</coins2:FloatProperty>
</coins2:hasProperties>
<coins2:creationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>2016-05-03T12:27:13.604Z</coins2:creationDate>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
</coins2:Object>
</rdf:RDF>Opening an existing container is a lot like starting a new one.
// Start container
JenaModelFactory factory = new JenaModelFactory();
JenaCoinsContainer ccr = new JenaCoinsContainer(factory, "C:\\bench_tutorial\\bench.zip", "http://demo.nl#");
var result = ccr.query("SELECT * WHERE { GRAPH ?g {?s <http://www.coinsweb.nl/cbim-2.0.rdf#name> ?o}}");
while(result.hasNext())
{
var row = result.next();
Console.WriteLine(row.ToString());
}The result is:
{g=http://www.coinsweb.nl/cbim-2.0.rdf#, s=http://www.coinsweb.nl/cbim-2.0.rdf#COINSTechnicalManagementGroup, o=COINS Technical Management Group}
Press any key to exit.// Start container
JenaModelFactory factory = new JenaModelFactory();
JenaCoinsContainer ccr = new JenaCoinsContainer(factory, "http://demo.nl#");
// Create individual
Object bench = new Object(ccr, "http://demo.nl#Object_Zitbank");
// Connect individuals
Connection connection = new Connection(ccr, "http://demo.nl#Zitbank_staat_op_Perron");
connection.addHasConnectedObjects("http://demo.nl#Object_Perron");
connection.addHasConnectedObjects(bench);
// Individuals with multiple types
bench.addType(typeof(Assembly));
Assembly benchAsAssembly = (Assembly)bench.@as(typeof(Assembly));
Object steunLinks = new Object(ccr, "http://demo.nl#Object_SteunLinks");
steunLinks.addType(typeof(Part));
steunLinks.setName("SteunLinks");
ContainsRelation contains = new ContainsRelation(ccr, "http://demo.nl#Zitbank_contains_SteunLinks");
contains.setHasPart((Part)steunLinks.@as(typeof(Part)));
benchAsAssembly.addHasContainsRelation(contains);
ccr.export("C:\\bench_tutorial\\bench.zip");<rdf:RDF
xmlns="http://demo.nl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:coins2="http://www.coinsweb.nl/cbim-2.0.rdf#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://demo.nl#">
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.coinsweb.nl/coins2/referencemodel/BranchVersioning#"/>
<owl:imports rdf:resource="http://www.coinsweb.nl/COINSWOA.rdf#"/>
<owl:imports rdf:resource="http://www.coinsweb.nl/units-2.0.rdf#"/>
<owl:imports rdf:resource="http://www.coinsweb.nl/cbim-2.0.rdf#"/>
<coins2:containerId rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>2bb795ed-bfd5-48f4-a874-cee575916460</coins2:containerId>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
</owl:Ontology>
<coins2:Connection rdf:ID="Zitbank_staat_op_Perron">
<coins2:hasConnectedObjects>
<coins2:Assembly rdf:ID="Object_Zitbank">
<coins2:hasContainsRelation>
<coins2:ContainsRelation rdf:ID="Zitbank_contains_SteunLinks">
<coins2:hasPart>
<coins2:Part rdf:ID="Object_SteunLinks">
<coins2:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>SteunLinks</coins2:name>
<coins2:creationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>2016-05-03T13:26:19.857Z</coins2:creationDate>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
<rdf:type rdf:resource="http://www.coinsweb.nl/cbim-2.0.rdf#Object"/>
</coins2:Part>
</coins2:hasPart>
<coins2:creationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>2016-05-03T13:26:20.636Z</coins2:creationDate>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
</coins2:ContainsRelation>
</coins2:hasContainsRelation>
<coins2:creationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>2016-05-03T13:26:17.394Z</coins2:creationDate>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
<rdf:type rdf:resource="http://www.coinsweb.nl/cbim-2.0.rdf#Object"/>
</coins2:Assembly>
</coins2:hasConnectedObjects>
<coins2:hasConnectedObjects rdf:resource="#Object_Perron"/>
<coins2:creationDate rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"
>2016-05-03T13:26:18.383Z</coins2:creationDate>
<coins2:creator rdf:resource="http://sandbox.coinsweb.nl/defaultUser"/>
</coins2:Connection>
</rdf:RDF>