Get all "someValuesFrom" of an object property class with Jena - jena
I want to get all the values of "someValuesFrom" of each Object Property as a list.
I have this part of an owl file:
<owl:Class rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#ErgativeFrame">
<owl:equivalentClass>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#hasAgent"/>
<owl:someValuesFrom>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Animal"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Object"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Person"/>
</owl:unionOf>
</owl:Class>
</owl:someValuesFrom>
</owl:Restriction>
</owl:equivalentClass>
<owl:equivalentClass>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#hasMainAction"/>
<owl:someValuesFrom rdf:resource="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#ErgativeVerb"/>
</owl:Restriction>
</owl:equivalentClass>
<owl:equivalentClass>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#hasOptionalPatient"/>
<owl:someValuesFrom>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Animal"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Beverage"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#BodyPart"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#ClosedLocation"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Clothing"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Food"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Furniture"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#NatureElement"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#NaturePhenomenon"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#OpenLocation"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Person"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Toy"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Transport"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Vegetal"/>
</owl:unionOf>
</owl:Class>
</owl:someValuesFrom>
</owl:Restriction>
</owl:equivalentClass>
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Frame"/>
</owl:Class>
I've tried something like this:
OntClass ontClass = this.ontModel.getOntClass(NS_OWL + "ErgativeFrame");
List<OntClass> list = ontClass.listEquivalentClasses().toList();
for (OntClass equiv: list) {
if (equiv.isRestriction()) {
System.out.println("is restriction");
System.out.println(equiv.getLocalName());
}
}
The quantity of "is restriction" printed on the screen is equal to the length of properties, but getLocalName is always "null".
What do I have to do?
EDIT: I've got the name of property correctly doing some changes in the code (see below).
Now I still can't get the "someValueFrom".
OntClass ontClass = this.ontModel.getOntClass(NS_OWL + "ErgativeFrame");
List<OntClass> list = ontClass.listEquivalentClasses().toList();
for (OntClass equiv: list) {
if (equiv.isRestriction()) {
System.out.println("is restriction");
System.out.println(equiv.asRestriction().getOnProperty().getLocalName());
}
}
The reason why getLocalName is returning null is because you are using anonymous classes and properties, i.e. classes and properties without assigned URIs. Since Jena cannot find the URI, it returns null.
To illustrate, here is a subset of your ontology with named classes and properties rather than anonymous classes and properties:
<rdf:Description rdf:about="http://www.w3.org/2002/07/owl#topObjectProperty">
<rdfs:range rdf:resource="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#AnimalObjectPerson"/>
</rdf:Description>
<owl:Class rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Frame"/>
<owl:Class rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Object"/>
<owl:Class rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Person"/>
<owl:Class rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Animal"/>
<owl:Class rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#AnimalObjectPerson">
<owl:equivalentClass>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Animal"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Object"/>
<rdf:Description rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Person"/>
</owl:unionOf>
</owl:Class>
</owl:equivalentClass>
</owl:Class>
<owl:Class rdf:about="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#ErgativeFrame">
<owl:equivalentClass>
<owl:Restriction>
<owl:onProperty rdf:resource="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#hasAgent"/>
<owl:someValuesFrom rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
</owl:Restriction>
</owl:equivalentClass>
<rdfs:subClassOf rdf:resource="http://www.semanticweb.org/gumaro/ontologies/2017/11/untitled-ontology-26#Frame"/>
</owl:Class>
and here is the code for retrieving the range of the property:
OntClass ontClass = ontModel.getOntClass(NS_OWL + "ErgativeFrame");
List<OntClass> list = ontClass.listEquivalentClasses().toList();
for (OntClass equiv: list) {
if (equiv.isRestriction()) {
OntProperty ontProperty = equiv.asRestriction().getOnProperty();
OntResource range = ontProperty.getRange();
List<OntClass> rangeList = range.asClass().listEquivalentClasses().toList();
for (OntClass rangeEquiv: rangeList) {;
for (OntClass rangeUnionClass: rangeEquiv.asUnionClass().listOperands().toList()) {
System.out.println("classes in union = " + rangeUnionClass);
}
}
}
}
I hope that helps.
In the provided snippet there is ambiguous situation: the restriction ...#hasMainAction + ...#ErgativeVerb could be either Data or Object Property Existential Quantification Restriction (for more about this see owl2 guide).
There are no explicit declarations in the snippet to judge what it is exaclty.
All Restrictions are anonymous resources (class expressions) - that's why they have no uri and local name therefore.
Jena-API (the package org.apache.jena.ontology) is only for outdated OWL-1, not OWL-2.
But there is a jena-based analogue of org.apache.jena.ontology.OntModel - special for OWL-2: com.github.owlcs.ontapi.jena.model.OntModel.
Although it is not directly related to the original question, it might be more useful in this case.
Here is an example:
String fullOwlAsString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<rdf:RDF xmlns=\"http://www.semanticweb.org/owlapi/test#\"\n" +
" xml:base=\"http://www.semanticweb.org/owlapi/test\"\n" +
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\"\n" +
" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n" +
" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n" +
" xmlns:owl=\"http://www.w3.org/2002/07/owl#\">" +
"<owl:Ontology rdf:about=\"#\" />" + yourSnippet + "</rdf:RDF>";
InputStream in = new ByteArrayInputStream(fullOwlAsString.getBytes(StandardCharsets.UTF_8));
OntModel ont = OntManagers.createONT().loadOntologyFromOntologyDocument(in).asGraphModel();
ont.ontObjects(OntClass.ObjectSomeValuesFrom.class).map(x -> x.getValue())
.filter(x -> x.canAs(OntClass.ComponentsCE.class))
.map(x -> (OntClass.ComponentsCE<? extends OntObject>)x.as(OntClass.ComponentsCE.class))
.flatMap(x -> x.getList().members())
.filter(RDFNode::isResource).map(RDFNode::asResource).map(Resource::getLocalName)
.forEach(System.out::println);
And the output:
Animal
Beverage
BodyPart
ClosedLocation
Clothing
Food
Furniture
NatureElement
NaturePhenomenon
OpenLocation
Person
Toy
Transport
Vegetal
Animal
Object
Person
Related
IOS Swift3 DES,ECB,Padding Encryption
Below is my android java code, actually how to write this in IOS Swift3? final SecretKey key = new SecretKeySpec(keyBytes, "DESede"); final Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); final byte[] cipherText = cipher.doFinal(plainTextBytes);
Find an AES or DES Common Crypto example here on SO and make changes as necessary to 3DES. Be sure the key is 24-bytes. Change: algorithm: CCAlgorithm3DES mode: kCCModeECB options: ccPKCS7Padding If the key is 16-bytes it is two-key 3DES, duplicate and append the first 8-bytes to the end of the key to create a 24-byte key. Note: DESede known as 3DES or Tripple-DES. 3DES is really not secure, especially 2-key 3DES. If at all possible update to AES-CBC with a random IV. Here is untested Swift 3 (Should also work with Swift4)code, note the warning about the key length above: func trippleDESCrypt(data:Data, keyData:Data, ivData:Data, operation:Int) -> Data? { let cryptLength = size_t(data.count + kCCBlockSize3DES) var cryptData = Data(repeating:0, count:cryptLength) var numBytesEncrypted :size_t = 0 let keyLength = keyData.count let algoritm: CCAlgorithm = UInt32(kCCAlgorithm3DES) let options: CCOptions = UInt32(kCCOptionPKCS7Padding | kCCModeECB) let cryptStatus = cryptData.withUnsafeMutableBytes {cryptBytes in data.withUnsafeBytes {dataBytes in ivData.withUnsafeBytes {ivBytes in keyData.withUnsafeBytes {keyBytes in CCCrypt(CCOperation(operation), algoritm, options, keyBytes, keyLength, ivBytes, dataBytes, data.count, cryptBytes, cryptLength, &numBytesEncrypted) } } } } if UInt32(cryptStatus) == UInt32(kCCSuccess) { cryptData.count = numBytesEncrypted } else { print("Error: \(cryptStatus)") return nil } return cryptData } As usual you need to have a Bridging Header file that contains the import: #import <CommonCrypto/CommonCrypto.h> and you need to include the framework: Security.framework.
DBus: returning a file descriptor
I want to implement a DBus service that returns a file descriptor, but this error is raised: ** (process:3419): WARNING **: Cannot marshal type "(null)" in variant ** (process:3419): CRITICAL **: unable to append OUT arg of type GValue for create_connection: ((GValue*) 0x647730) Program received signal SIGSEGV, Segmentation fault. 0x00007ffff6fcd5b9 in g_type_check_value () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 The interface I have implemented looks like this: <node name="/org/designfu/IceService"> <interface name="org.designfu.IceService"> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="ice_service"/> <method name="create_connection"> <!-- This is optional, and in this case is redunundant --> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="ice_service_create_connection"/> <arg type="b" name="controlling_mode" direction="in" /> <arg type="b" name="upnp" direction="in" /> <arg type="s" name="dbus_path" direction="out" /> <arg type="s" name="username_fragment" direction="out" /> <arg type="s" name="password" direction="out" /> <arg type="v(h)" name="send_fd" direction="out" /> <arg type="v(h)" name="recv_fd" direction="out" /> </method> </interface> </node> and this is my implementation: gboolean ice_service_create_connection(IceService *obj, const gboolean controlling_mode, const gboolean upnp, char **dbus_conn_path, char **username_fragment, char **password, GVariant **send_fd, GVariant **recv_fd, GError **error) { IceConnection *conn; gboolean res; conn = g_object_new(ICE_CONNECTION_TYPE, "controlling-mode", controlling_mode, "upnp", upnp, NULL); /* register dbus path */ char uuid_str[] = "123"; char dbus_path[512]; g_snprintf(dbus_path, 512, "/org/designfu/IceService/object/%s", uuid_str, NULL); dbus_g_connection_register_g_object(bus, dbus_path, G_OBJECT(conn)); /* set output parameters */ *dbus_conn_path = g_strdup(dbus_path); res = ice_connection_get_local_credentials(conn, username_fragment, password); g_assert(res); *send_fd = g_variant_new("(h)", conn->their_sock[SEND]); *recv_fd = g_variant_new("(h)", conn->their_sock[RECV]); g_assert(*send_fd); g_assert(*recv_fd); return TRUE; } If I leave out the send_fd and recv_fd output parameters, the functions works like a charm. However, somehow I have an error in passing the file descriptors to the dbus. The descriptors were created using int domain = AF_LOCAL; int type = SOCK_STREAM; int protocol = 0; err = socketpair(domain, type, protocol, sock); Does anyone have a clue what's wrong here?
v(h) doesn't look like a valid DBus type signature, are you sure you don't mean (h)?
ASP.NET MVC2 and IIS 7.5 . Problems when read large data from Excel 2010
I have a problem when reading large amount of data from Excel 2010 I use the code below to read data: public static DataTable GetExcelData(string filePath, string extension) { try { string conStr = ""; switch (extension) { case ".xls": //Excel 97-03 //conStr = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString; //conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR={YES}'"; conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=Excel 12.0;"; break; case ".xlsx": //Excel 07 //conStr = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString; conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=Excel 12.0;"; break; } //conStr = String.Format(conStr, filePath, true); OleDbConnection connExcel = new OleDbConnection(conStr); OleDbCommand cmdExcel = new OleDbCommand(); OleDbDataAdapter oda = new OleDbDataAdapter(); DataTable dt = new DataTable(); cmdExcel.Connection = connExcel; //Get the name of First Sheet log.Debug("Excel ConnectionString = " + conStr); connExcel.Open(); log.Debug("Open Excel connection ok"); DataTable dtExcelSchema; dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString(); connExcel.Close(); log.Debug("SHEET NAME = " + SheetName); //Read Data from First Sheet connExcel.Open(); cmdExcel.CommandText = "SELECT * From [" + SheetName + "]"; oda.SelectCommand = cmdExcel; oda.Fill(dt); connExcel.Close(); return dt; } catch(Exception ex) { log.Debug("GetExcelData Error:" + ex.ToString()); return null; } } My ASP.NET MVC 2.0 project works correctly when running on Visual Studio 2010 with both a small Excel file and a large Excel file. But, when I deploy to IIS 7.5 (windows 7 pro), my website only works correctly with small Excel file. With a large excel file, it throw the following error: GetExcelData Error:System.Data.OleDb.OleDbException (0x80004005): External table is not in the expected format. at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OleDb.OleDbConnection.Open() (On IIS 7.5, my website uploads large file Excel success) How can I fix this?
It might be a web.config change that is needed to allow larger files over 4MB. You can add the following to the web.config to allow this, <configuration> <system.web><!-- maxRequestLength (KB) --> <httpRuntime maxRequestLength="10000" executionTimeout="110"/> </system.web> </configuration> This may help, Maximum request length exceeded I use the following connection string where '{0}' is the file path, for .xls files, strConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0};Extended Properties= ""Excel 12.0 Xml;HDR=YES;IMEX=1""" and for .xlsx files I use, strConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES"""; It won't be the size of the files if you have set up the web.config up. I would try and save the file as an 97-2003 workbook .xls file and use the relevant connection string. If you are hosting this on a server, the server will need the Office drivers needed to process the file. UPDATE Set HDR to No and go through each row dismissing the header row. This will avoid a data type issue that occurs when the columns are checked for the data type.
Jena changes my owl file after adding an instance
I have an owl file created with protege 4.2. when I add some Instance with Jena, Jena changes the file structure but the file extension remains the same (.owl) the file is readable in protege with some error. Anyone knows where is the problem with my code? Because the result of the sparql query is somehow strange after the edit with Jena. For example, Before editing with Jena <owl:NamedIndividual rdf:about="&ontologies;thesis_ontology_1try#AM6"> <rdf:type rdf:resource="&ontologies;thesis_ontology_1try#ApplicationModel"/> <hasID rdf:datatype="&xsd;string">20125157-d62b-45de-8809-84186c7169b5AM6</hasID> <name rdf:datatype="&xsd;string">Gebäudemodell / Buildingmodel</name> <hasContent rdf:resource="&ontologies;cpixml"/> <hasLevelOfDetail rdf:resource="&ontologies;thesis_ontology_1try#4"/> <hasDomain rdf:resource="&ontologies;thesis_ontology_1try#BIM"/> <hasType rdf:resource="&ontologies;thesis_ontology_1try#Object"/> <hasPhase rdf:resource="&ontologies;thesis_ontology_1try#SLCT"/> <hasContent rdf:resource="&ontologies;thesis_ontology_1try#ifc"/> </owl:NamedIndividual> After Jena <rdf:Description rdf:about="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#AM6"> <hasContent rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/cpixml"/> <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/> <hasDomain rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#BIM"/> <hasType rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#Object"/> <hasID rdf:datatype="http://www.w3.org/2001/XMLSchema#string">20125157-d62b-45de-8809-84186c7169b5AM6</hasID> <hasPhase rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#SLCT"/> <rdf:type rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#ApplicationModel"/> <hasContent rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#ifc"/> <name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Gebäudemodell / Buildingmodel</name> <hasLevelOfDetail rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#4"/> <rdf:type rdf:nodeID="A28"/> <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/> <rdf:type rdf:nodeID="A29"/> <rdf:type rdf:nodeID="A30"/> <rdf:type rdf:nodeID="A31"/> <rdf:type rdf:nodeID="A32"/> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/> <rdf:type rdf:nodeID="A33"/> <rdf:type rdf:nodeID="A34"/> <rdf:type rdf:nodeID="A12"/> <rdf:type rdf:nodeID="A15"/> <rdf:type rdf:nodeID="A35"/> <rdf:type rdf:nodeID="A5"/> <Linkedby rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#LM2"/> <isAMof rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#MMC2"/> And This is the code public static void main(String[] args) throws IOException { InputStream in = FileManager.get().open("./src/thesis_ontology_1try.owl"); OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, null); model.read(in, null); in.close(); String NS = "http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#"; OntClass ApplicationModel = model.getOntClass(NS + "ApplicationModel"); Individual dom = model.getIndividual(NS + "RFP"); Individual pha = model.getIndividual(NS + "SLCT"); Individual lev = model.getIndividual(NS + "3"); Individual new1 = model.createIndividual(NS + "new1", ApplicationModel); ObjectProperty domain = model.createObjectProperty(NS +"hasDomain"); ObjectProperty phase = model.createObjectProperty(NS +"hasPhase"); ObjectProperty lod = model.createObjectProperty(NS +"hasLevelOfDetail"); model.add(new1, domain, dom); model.add(new1, phase, pha); model.add(new1, lod, lev); PrintStream p= new PrintStream("./src/thesis_ontology_1try.owl"); model.writeAll(p, "RDF/XML", null); p.close(); System.out.println("Done"); } }
model.writeAll(p, "RDF/XML", null); try "RDF/XML-ABBREV", the pretty printer. But either way, it's the same triples, written differently, and that's what matters.
iphone OS! RSA Encryption with public key generated by Bouncy Castle (Java)
I'm developing an application on iphone. I had an application on Java using encryption (RSA) and I created a Private Key and Public Key. I want use the Public Key in Java application on iphone. For Ex: My Public Key is byte[] publicKey = {0x01,0x02}; How can I use my publicKey to encrypt data on iphone? I saw CryptoExercise, but i cannot build it (function: SecKeyEncrypt err:EXC_BAD_ACCESS ). Can i use getPublicKeyBits() or getPublicKeyRef()? Here is my code: * (NSData *)getPublicKeyBits { OSStatus sanityCheck = noErr; // const char myByteArray[] = { 0x00, -0x79, 0x7C, 0x34, 0x5C, -0x36, 0x36, 0x75, 0x0E, 0x7F, -0x21, -0x05, 0x41, 0x21, 0x4F, -0x30, 0x2D, 0x5F, 0x08, -0x25, 0x07, -0x08, 0x22, -0x09, 0x32, -0x6C, 0x10, 0x1E, 0x5A, -0x59, -0x14, -0x55, -0x73, 0x21, 0x5E, -0x54, -0x5E, -0x72, 0x37, -0x31, -0x25, -0x45, 0x3B, 0x7D, -0x3C, -0x6F, -0x40, -0x7E, 0x74, -0x68, -0x23, 0x42, 0x12, -0x62, -0x66, 0x4D, 0x20, -0x69, 0x28, -0x28, -0x36, -0x71, 0x21, 0x02, -0x32, -0x19, 0x66, 0x7D, 0x3E, 0x03, 0x49, -0x66, 0x1F, -0x38, 0x3C, 0x0A, 0x5F, 0x60, 0x1B, -0x75, 0x41, 0x48, -0x5F, 0x1F, -0x34, -0x31, -0x09, 0x17, 0x23, 0x11, 0x1E, -0x68, 0x0B, -0x4D, 0x69, -0x3F, -0x27, 0x13, -0x71, -0x6D, -0x7A, 0x3A, 0x64, 0x2A, 0x6A, -0x6E, 0x3C, 0x04, -0x70, -0x1C}; NSData *publicKeyBits = NSData dataWithBytes: myByteArray length: sizeof(myByteArray); // //NSData * publicKeyBits = {1}; NSMutableDictionary * queryPublicKey = [NSMutableDictionary alloc] init; // Set the public key query dictionary. queryPublicKey setObject:(id)kSecClassKey forKey:(id)kSecClass; queryPublicKey setObject:publicTag forKey:(id)kSecAttrApplicationTag; queryPublicKey setObject:(id)kSecAttrKeyTypeRSA forKey:(id)kSecAttrKeyType; [queryPublicKey setObject:NSNumber numberWithBool:YES] forKey:(id)kSecReturnData; // Get the key bits. sanityCheck = SecItemCopyMatching((CFDictionaryRef)queryPublicKey, (CFTypeRef *)&publicKeyBits); if (sanityCheck != noErr) { printf("sanitycheck error#####"); publicKeyBits = nil; } NSLog(#"** public key bits: %s", &publicKeyBits); queryPublicKey release; return publicKeyBits; } // encrypt message * (void)encryptWithPublicKey:(uint8_t *)plainBuffer cipherBuffer:(uint8_t *)cipherBuffer { NSLog(#"== encryptWithPublicKey()"); NSData* publicKey= [AppController sharedWrapper] getPublicKeyBits; OSStatus status = noErr; NSLog(#"** original plain text 0: %s", plainBuffer); size_t cipherBufferSize = 1; uint8_t *pPlainText = (uint8_t*)"This is a test"; uint8_t *aCipherText; size_t *iCipherLength = (size_t*)"1024"; // Error handling // Encrypt using the public. printf("begin ecrypt !!!!"); // status = SecKeyEncrypt(publicKey, // kSecPaddingNone, // plainBuffer, // plainBufferSize, // &cipherBuffer[0], // &cipherBufferSize // ); status = SecKeyEncrypt(publicKey, kSecPaddingNone, pPlainText, strlen( (char*)pPlainText) + 1, aCipherText, iCipherLength); printf("end encrypt !!!!"); NSLog(#"encryption result code: %d (size: %d)", status, cipherBufferSize); NSLog(#"encrypted text: %s", cipherBuffer); } Please Help me! Thank you very much
I'm not 100% following it, but I think your issue could be as follows: Public/Private key pairs are not used to encrypt data. They are used only to encrypt fixed-size blocks of data, which are short - on the order of the size of the public/private key themselves. So they way these are used is that the public/private key is used to encrypt [something like] an AES Key - which in-turn is used with a mode (like EBC, etc) to encrypt a stream, or irregularly-sized block of data. I think you are trying to use the Public/Private keypair to encrypt your user-data, which is likely not the correct size for the public/private key operations - thus your leaking and getting an BAD_ACCESS_ERROR.