I try to use ManchesterOWLSyntaxParser from OWL-API. I need to convert String in Manchester syntax to OWL Axiom, which I can add to existing ontology. The problem is, that I always get Parser Exception (something like bellow):
Exception in thread "main" org.semanticweb.owlapi.manchestersyntax.renderer.ParserException: Encountered Class: at line 1 column 1. Expected one of:
Class name
Object property name
Data property name
inv
Functional
inverse
InverseFunctional
(
Asymmetric
Transitive
Irreflexive
{
Symmetric
Reflexive
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl$ExceptionBuilder.build(ManchesterOWLSyntaxParserImpl.java:2802)
at org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxParserImpl.parseAxiom(ManchesterOWLSyntaxParserImpl.java:2368)
at Main.main(Main.java:29)
I have read about Manchester syntax at w3c website, but I don't know where the problem is. Maybe manchester parser should be used in different way.
Code with example of string in Manchester syntax, which I have tried to parse.
OWLOntology o = ontologyManager.loadOntologyFromOntologyDocument(new File("family.owl"));
OWLDataFactory df = o.getOWLOntologyManager().getOWLDataFactory();
ManchesterOWLSyntaxParser parser = new ManchesterOWLSyntaxParserImpl(ontologyManager.getOntologyConfigurator(), df);
parser.setStringToParse("Class: <somePrefix#Father>" +
" EquivalentTo: \n" +
" <somePrefix#Male>\n" +
" and <somePrefix#Parent>");
OWLAxiom ax = parser.parseAxiom();
The ontology does not have declarations for the classes and properties in the fragment. The parser cannot parse the fragment without knowing the entities involved.
Just like parsing a whole ontology, classes, properties and data types need declaration axioms in the ontology object.
Related
I have implemented a custom bridge which maps all the dynamic fields with related types. Types can be of FieldType.STRING or FieldType.DOUBLE or FieldType.BOOLEAN based on the value.
When I looked on the mapping on my elastic search schema, all the string fields are mapped with type TEXT where I expect it to be a keyword so that I can do a wildcard serach.
Here is my problem I want to filter "AAA-VALUE" for dynamically mapped field 'attribute.dynamic-field-1'
I have an indexed value as "AAA-VALUE" for dynamically mapped field 'attribute.dynamic-field-1'
If I want to do a keyword search, I faced error like 'Field bridge is not found' then I resolved the error by ignoring the bridge using ignoreFieldBridge and the error is gone.
Then again I tried to do a search with value as "AAA-VALUE" and the result is empty (no data found). Here I created the query using a keyword() query.
Then again I tried to do a phrase query then it got worked but the problem is how I can do a wild card search like '-VALUE'.
Regarding code, I followed similar implementation as given here https://github.com/hibernate/hibernate-search/blob/master/legacy/engine/src/test/java/org/hibernate/search/test/bridge/MultiFieldMapBridge.java
Only the type differs in my implementation, where the type can be a string or boolean or double.
My hibernate search version - hibernate-search.version and hibernate-search-elasticsearch = 5.11.3.Final
It got to work after doing below changes.
This how I added the fields before
public class MultiFieldMapClassBridge implements MetadataProvidingFieldBridge {
;
;
;
luceneOptions.addFieldToDocument( fieldPrefix + "." + key, value, document );
}
But the fields should be added as below.
public class MultiFieldMapClassBridge implements MetadataProvidingFieldBridge {
;
;
org.apache.lucene.document.Field field = new org.apache.lucene.document.StringField(fieldPrefix + "." + key, value, luceneOptions.getStore());
document.add(field);
}
I written the wild card query as below
queryBuilder.keyword().wildcard().onField(prefixedPath).ignoreFieldBridge().matching(String.format("*%s*", matchingString.toLowerCase(Locale.getDefault()))).createQuery();
I realised this after reading this doc where the class bridges have to add the field as StringField.
https://docs.jboss.org/hibernate/search/5.5/reference/en-US/html_single/#example-class-bridge
I have an ontology, created using Protegé 4.3.0, and I would use the OWL-API in order to add some OWLNamedIndividual objects to a file OWL. I use the following instruction in order to create a new OWLNamedIndividual:
OWLNamedIndividual objSample = df.getOWLNamedIndividual(IRI.create(iri + "#" + id));
the variable id is a String;
iri is the base IRI of the loaded ontology; in order to get the base IRI of the ontology, I used the following instruction: iri = ontology.getOntologyID().getOntologyIRI().
So the new OWLNamedIndividual is added to the loaded ontology and then the ontology is saved to OWL file using the following instruction.
XMLWriterPreferences.getInstance().setUseNamespaceEntities(true);
OWLOntologyFormat format = manager.getOntologyFormat(ontology);
manager.saveOntology(ontology, format, IRI.create(file.toURI()));
The variable id is a String generated from the base name of a file (ie. the file name without the extension). If the base name of the file has one or more spaces in the name, the ontology is saved without any error, but when I open the newly saved OWL file, Protegé reports a parsing error at the first occurrence of the IRI containing spaces.
How could I create a valid IRI for an OWLNamedIndividual object using the base IRI of loaded ontology and the base name of a file?
IRIs are suppose to be a block that represents your resource. If I understand you correctly you have an id such as big boat and you are creating IRIs that look like <http://example.com#big boat>. This is not a valid IRI, and you need to replace the space with an _ or a -, such that you have <http://example.com#big_boat>. Even if you enter a modelling element name with a space in Protégé, it automatically will put a _ in the middle.
Take a look at the this article for the invalid characters in an IRI.
Systems accepting IRIs MAY also deal with the printable characters in
US-ASCII that are not allowed in URIs, namely "<", ">", '"', space,
"{", "}", "|", "\", "^", and "`", in step 2 above. If these
characters are found but are not converted, then the conversion
SHOULD fail.
I’m looking for a Java library that can read/write a list of “simple objects” from/to a CSV file.
Let’s define a “simple object” as a POJO that all its fields are primitive types/strings.
The matching between an object’s field and a CSV column must be defined according to the name of the field and the title (first row) of the column - the two must be identical. No additional matching information should be required by the library! Such additional matching information is a horrible code duplication (with respect to the definition of the POJO class) if you simply want the CSV titles to match the field names.
This last feature is something I’ve failed to find in all the libraries I looked at: OpenCSV, Super CSV and BeanIO.
Thanks!!
Ofer
uniVocity-parsers does not require you to provide the field names in your class, but it uses annotations if you need to determine a different name, or even data manipulation to be performed. It is also way faster than the other libraries you tried:
class TestBean {
#NullString(nulls = { "?", "-" }) // if the value parsed in the quantity column is "?" or "-", it will be replaced by null.
#Parsed(defaultNullRead = "0") // if a value resolves to null, it will be converted to the String "0".
private Integer quantity; // The attribute name will be matched against the column header in the file automatically.
#Trim
#LowerCase
#Parsed
private String comments;
...
}
To parse:
BeanListProcessor<TestBean> rowProcessor = new BeanListProcessor<TestBean>(TestBean.class);
CsvParserSettings parserSettings = new CsvParserSettings();
parserSettings.setRowProcessor(rowProcessor);
parserSettings.setHeaderExtractionEnabled(true);
CsvParser parser = new CsvParser(parserSettings);
//And parse!
//this submits all rows parsed from the input to the BeanListProcessor
parser.parse(new FileReader(new File("/examples/bean_test.csv")));
List<TestBean> beans = rowProcessor.getBeans();
Disclosure: I am the author of this library. It's open-source and free (Apache V2.0 license).
This is the first time i am using a YAML parser and I am currently stuck at this point
I have a config file which goes something like
Users
-Name:A
Id : x
Addr:10.0.0.1
-Name:B
Id :y
Addr:10.0.0.2
HomeAddress
City:bla bla
Country:bla bla
Office Address
City:abchd
Country:bha bha ba
So I thought the best way to parse it would be to have a list like this.
List<Map<String, obj>> Object = (List<Map<String, obj>>) yaml.load(input);
Objective was to access the object by specifying a string. Like Username A, I shld be able to obtain his id and IPAddr (This is the most important to me at the moment). But when I tried this declaration, I got an error like this
Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.util.List
at Message.MessagePasser.<init>(MessagePasser.java:34)
Can someone please help me debug this. I am running by a deadline!!:(
The YAML parser seems to be returning a Map. So you should use it like this:
Map config = (Map) yaml.load(input);
Map usersConfig = config.get("Users");
Also what particular YAML parser are you using?
Update 1: If you look at the documentation, the load method either returns a List or Map depending on the contents of your YAML file. As your YAML file starts with a key-value mapping (Users) and not an array (-), the load method returns a Map which is the appropriate type to be returned in this case.
1) check the validity of your YAML here: http://instantyaml.appspot.com/
2) Your document should look like this: (mind the spaces !)
Users :
- Name : A
Id : x
Addr : 10.0.0.1
- Name : B
Id : y
Addr : 10.0.0.2
I have this entity - I'm trying to determine the type of its properties - in Google App Engine's internal data-types PREFERRED (as opposed to Java data types).
The below code is obviously simplified. In reality I do not know the entity's properties or anything else about it.
final DatastoreService dss = DatastoreServiceFactory.getDatastoreService();
final Query query = new Query("Person");
final PreparedQuery pq = dss.prepare(query);
for (Entity entity : pq.asIterable())
{
final Object property = entity.getProperty("some_property");
// Here I want to determine which data type 'property' represents - GAE-wise.
}
In App Engine's Java code I've found some hints:
DataTypeTranslator
DataTypeTranslator.typeMap (internal private member)
Property.Meaning.GD_PHONENUMBER
I'm unable to link those together into what I need - some sort of reflection.
I wish I was able to do something like this:
entity.getPropertyType("some_property");
Does anyone know better?
DataTypeTranslator source code here
Edit #1: <<
INGORE this one. It's me who put these postfixes (I was confused by the doc).
Here's more important info I've found.
I'm getting it in Eclipse' tool-tip mini-window when I point over an entity (one which I just fetched from the Datastore).
The Datastore seems to send it (this payload) as raw text which is nice, maybe I'll have to parse it (but, how do I get it from code LOL).
Pay attention to the types in here, it's written plain simple.
Here it is:
<Entity [Bird(9)]:
Int64Type:44rmna4kc2g23i9brlupps74ir#Int64Type = 1234567890
String:igt7qvk9p89nc3gjqn9s3jq69c = 7tns1l48vpttq5ff47i3jlq3f9
PhoneNumber:auih50aecl574ud23v9h4rfvt1#PhoneNumberType = 03-6491234
Date:k1qstkn9np0mpb6fp41cj6i3am = Wed Jul 20 23:03:13 UTC 2011
>
For example, property named String:igt7qvk9p89nc3gjqn9s3jq69c has the value of 7tns1l48vpttq5ff47i3jlq3f9 and it doesn't tell its type. Also property Date:k1qstkn9np0mpb6fp41cj6i3am.
Property named Int64Type:44rmna4kc2g23i9brlupps74ir has the value of "1234567890" and here it strictly mentions that the data type is of "Int64Type".
I'm searching for it too.
It's a bit of a hack, but at least my output includes the type (without needing a secret decoder ring). But my code is slightly different:
Query allusersentityquery = new Query();
allusersentityquery.setAncestor(userKey);
for (final Entity entity : datastore.prepare(allusersentityquery).asIterable()) {
Map<String, Object> properties = entity.getProperties();
String[] propertyNames = properties.keySet().toArray(
new String[properties.size()]);
for(final String propertyName : propertyNames) {
// propertyNames string contains
// "com.google.appengine.api.datastore.PostalAddress" if it is a Postal Address
}
}
There seems to be no documents about determining the Property Types here.