-2

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

user2083529
  • 715
  • 3
  • 13
  • 25
  • "I know this question was asked earlier but there is no proper solution anywhere right now so i am going to ask it again." The proper thing to do in this case would be to offer a bounty on the existing question, update it with more information, etc. – Joshua Taylor Jan 15 '15 at 17:03
  • I am sure the OWL API can be used in Android apps because I and others have used it to load ontologies in JFact. I cannot recall if this worked with version 3.4.10 though. I'll answer with details once I have time to recreate. – Ignazio Jan 16 '15 at 00:06
  • @JoshuaTaylor sorry, if i knew that i might have done that. thanks for information – user2083529 Jan 16 '15 at 06:43
  • @Ignazio on which android version hv u tested that? and yeah, it will be helpful if u can manage time and answer this question with some details. – user2083529 Jan 16 '15 at 06:46
  • I've run it on 4.1.2 – Ignazio Jan 16 '15 at 10:47
  • i m getting file not found errors – user2083529 Jan 16 '15 at 15:56
  • @Ignazio can you please point out the problem now, i've rewritten the question. And yeah before i was making a small mistake in building path. – user2083529 Jan 16 '15 at 17:04
  • new File("assets/Pizza.owl") seems to be looking for file paths starting in your root folder, which is not where the file is. You need to use the actual path, or bundle your file in the resources accessible in the classpath – Ignazio Jan 17 '15 at 20:44
  • @Ignazio well the file path is correct. i have placed my owl file is assets folder in android project. the problem with placing file in assets folder is the when we run our program in adk then the location of file is different in adk folder. there we have to use inputstream class. The File = new file class and methods do not simply work when our files are in assets fiolder. I am still trying to figure out the correct way as i hv to place the file in assets folder no where else – user2083529 Jan 18 '15 at 10:06
  • possible duplicate of [How to access file under assets folder in android?](http://stackoverflow.com/questions/12387637/how-to-access-file-under-assets-folder-in-android) – VenomVendor Jan 18 '15 at 10:57
  • @VenomVendor maybe this part is duplicate as i hv edited my post. but the main theme "Loading owl file in android" was still a mystery. and this post might help people who are learning ontologies. – user2083529 Jan 18 '15 at 11:31

1 Answers1

0

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);
user2083529
  • 715
  • 3
  • 13
  • 25
  • The question in its present form is only relevant for people looking for ways to open a file that is part of an apk assets. Can you add the details of the previous build error and how to fix it? Those might be relevant to another user having troubles with the OWL API. – Ignazio Jan 18 '15 at 17:12
  • @Ignazio sorry, i didn't get the term "previous build error". – user2083529 Jan 18 '15 at 20:48
  • You said there was a mistake in the build path when you had method not found error. – Ignazio Jan 19 '15 at 07:12