I know this question was asked earlier but there is no proper solution anywhere right now so i am going to ask it again. How can i load an owl file in my android project?
The code works in java but they are useless in android . When i try them in an android project then the file can not be accesed . I am using OWLApi 3.4.10. I am loading the ontology from my mainActivity class. The loading is performed in loadOntology method in OntologyClass class. In main method the coding is as
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ontologyClass ontology;
ontology = new ontologyClass();
try {
ontology.ontologyLoad();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The coding of ontologyClass is as:
@Ignore
@SuppressWarnings("javadoc")
public class ontologyClass {
OWLOntology pizza;
OWLOntologyManager manager;
public ontologyClass ontologyLoad() throws OWLOntologyCreationException {
manager= OWLManager.createOWLOntologyManager();
File file= new File("assets/Pizza.owl");
pizza = manager.loadOntologyFromOntologyDocument(file);
return this;
}
The pizza.owl file is inside the assets folder. In logcat i receive warnings like
FileNotFountException: /assets/Pizza.owl: open failed:ENOENT (no such file or directory)
can anyone fix this file loading problem?
Thanks
Tackling Build path error: Normally if you are using owl api in java then all you need is just to import the owl api library. But in android if you do only this you will still get error stating "method not found". So you need to perform a second step i.e right click your android project and then
properties-> Java Build Path -> order and export tab
and there check mark the OWLAPi 3.4.10.jar
the answer for the file path in assets folder is as follows:
The directory/path of theowl file in asserts folder can be accessed via InputStream class the File class doesn't work for this folder, so instead of using
File file= new File("assets/Pizza.owl");
use this code
InputStream is= myContext.getAssets().open("Pizza.owl");
and finally use the InputStream instance is, this represents the correct path of the file in assets folder ie
pizza = manager.loadOntologyFromOntologyDocument(is);