How to convert the data in Android DBs to rdf data? - android

I'm trying to extract rdf data from android DB.
It means that I want to get rdf data from contacts DB, callendar DB, and so on directly.
I know that the current android platform have used SQLite DB.
Is it available to extract rdf data?
Surely, I can make the same data typed of rdf manually.
Here, My converting criterion is that the table name means Subject of rdf, the column name means Predicate, and the value means Object.
But the important issue is how to convert data in the existing data in Android DB to RDF data automatically.
I found that the tools such as AndroJena, uJena, Sesame... don't support that functionality.
Help me plz.
PS)
I searched many posts here and I found that someone had stuggled with the similar problem.
He got the solution like below.
First, Copy ur android DB on your own DB in desktop.
Second, Nomalize the copied DB.
Third, Make rdf triples by utilizing the modified DB.
3.1. By referencing such papers titled as RDB to RDF and following the defined converting rules from those, convert data to the data typed of RDF.
Above solution is the only answer?

The general question of converting from a relational DB to RDF was covered by W3C's RDB2RDF working group. This group finished the standards they produced in 2012.
There are two styles, to just directly map to RDF (Direct Mapping) or to map using mapping rules in R2RML. If you convert directly then you can use all your favorite tools to map into the ontology want.
See the Implementation report for a list of implementations at the time it was written. There may be many other bits of software kicking around the web which do this sort of thing, which have been produced more recently or were not spotted then by the group.

The whole RDB2RDF issue is still very much under development. However, D2RQ precedes this discussion and we found this a useful tool to 'automatically' go from RDB to RDF. This only requires a mapping. The code is all in Java, so it is probably possible to adapt it and deploy it to your android phone.
A few notes: D2RQ is not under development anymore (as far as I know) and you still have to make a mapping on how to translate the relational database to rdf.

Related

How to use SQL Database other means of Data Storage

I have a SQL Database containing 24 Columns and about 24000 Rows. I want to retrieve data from that SQL Database. I am new to Android and don't know how to use it.
I found an Android library called Realm but I couldn't find a way of Converting SQL to Realm Database.
If there is a simple way to read data from and to store data in SQL Database or another way of storing data in Android in form of Database, please let me know.Any Help will be appreciated.
Thanks!!
android uses SQLite. This is very similar to SQL. You would only need to have the app download the data from the server database and copy in into the local database.
SQLite information can be found at http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
Converting from an SQL file has been discussed at Convert MySQL to SQlite
Android comes with SQLite, this is what you should use. did you search anything like "Android and sql"? android training on the subject
Edit:
so you dont have an sql file, you have an online MySql database. can use jdbc but it is not widely recomended. there are some alternatives as in here and here
Not sure if this will help, but . . .
I have been playing around with different programming options for my Android tablet. One is RFO Basic! freely available from the Google store. It seems to be a dialect of Dartmouth Basic with a lot of built-in hooks to Android specific functions (GPS, camera, etc) as well as an interface to SQL. The set of example programs that comes with the distribution includes and SQL example.
Being a Basic-language environment it will (1) be easy to learn but (2) probably slow (very slow) on a 24000 row table..
Hope this helps

Data transferring format

I need to download onto my devices some data in multiple files.
Then this data will be copied to application's local db (this is SQLite db, however in future this may be Compact SQL on WInPhone).
What is the best format for such files?
I am considering such possibilities:
SQLited db file - possibly this will be easy to copy to my db. My current prefferance.
JSON format. Maybe not enough compact because column name will be repeating.
CSV - it allows to store only one table but I would prefer have few tables in one file
XML - I do not see any prefferaces over json.
JSON is the most popular, human-readable, easy to use format. There's tons of supporting libraries, native and not, for all OSs. It's fast and reliable. You can easily update the data you pass with it without updating the apps (which you cannot by passing an SQLite database and would be difficult with a CSV file). XML is being slowly deprecated for data communications... but if you see some special advantage with XML (parsing the XML directly, which is not as effective with JSON yet, for example), go for it. I'd choose JSON anyway, it's the current standard and will still be for a long time.

Import iOS coredata into android sqlite

I want to share data between my android and iOS apps. I've exported core data sqlite from this directory,
~/Library/Application Support/iPhone Simulator/User/Applications//Documents/.sqlite
Which is fine I think. The problem arises when I've try to open the sqlite file with sqlite browser. As it gives an error, "Not a sqlite 3 file". I was thinking that I will import that coredata sqlite file into android.
However my question is, What is the proper way to import iOS coredata into android sqlite?
There's no really good way to take a SQLite file created by Core Data and use it anywhere else. Core Data is more than just a SQLite wrapper, it provides a rather different API with different rules and assumptions (for example, Core Data has true many-to-many relationships, so you don't need to create join tables). SQLite is an implementation detail. As a result, the schema in one of these SQLite files has only a passing resemblance to the Core Data object model. You could open the SQLite file anywhere, but making sense of it might be a problem.
If you want to use the same data and you're already using Core Data, you'll need to have your app export the data to something more portable-- CSV maybe, or a more generic SQLite file, or anything else that looks good to you.
If you're not already using Core Data and you need this portability, you might be better off using SQLite directly with whatever schema you need. You don't have to go through Core Data to use SQLite on iOS if it's not what you need. You can either use SQLite's API directly or else go via wrappers like PLDatabase or FMDB.
Core Data's SQLite store is a vanilla SQLite file, so something else is going wrong with your import. However the mapping that Core Data makes from its entities to the SQLite store is explicitly implementation dependent and, as a result, is not part of the specification and is therefore not documented. As it is allowed to change between versions of Core Data it's also not necessarily safe to reverse engineer it*.
As of iOS 5, if you really want to use Core Data and SQLite then what you can do is write your own NSIncrementalStore. That'll allow you to impose any mapping from Core Data to SQLite that you desire. The downside is that it's barely documented.
(*) although it is sometimes helpful to poke around in there; you can supply the command-line argument -com.apple.CoreData.SQLDebug 1 to have Core Data dump all the SQL commands it performs to the console, then it can be a helpful performance diagnostic to open your persistent store in SQLite and check out the query plans, to make sure you're indexing the correct things.
Have not export any iOS SQLite file so I dont know how do you export yours.
Maybe you need analysis your file bytes code? Look this http://www.sqlite.org/fileformat.html

Is there any way to extract queries from SQLite?

I'm trying to create some sort of backup & restore function in my app. Before that, I've been reading for a while to understand if it's possible to achieve, but I found out this question:
Sqlite DB Android Backup/Restore
The only other way I could see to do it, would be to read the actual contents of the DB and generate a file containing the SQL which which it can be restored from, this is obviously a more complex and doesn't offer any advantages to justify this complexity.
This answer, I think, is the best way to accomplish that; not explorting the .db file, but exporting queries.
You know; when you export a SQL data from mysql, you get a file which contains all the queries that creates the structure and queries that fill the structure with data.
That's what I'm trying to mimic; generate a file which contains sql queries from a .db file.
Do you guys think it's possible, I mean, is there any builtin method to achieve that?
Otherwise, if its too hard to handle, how do you manage to avoid what this user (https://stackoverflow.com/a/10842043/1943607) is talking about?
So, I disabled WAL with "PRAGMA journal_mode = DELETE" and then I was able to view the database in the browser and able to restore it on my test device fine.
That previous part, I can't understand it. Is this a configuration you set to sqlite?
Thanks
I haven't actually tried this with sqlite, but with mysql you could do things like create "dumps" of your database. Those dumps contained exactly what you describe: a set of queries that, when executed together, recreate the database, including the contents.
Judging from the "sqlite3" documentation found at http://www.sqlite.org/sqlite.html (especially the "Converting An Entire Database To An ASCII Text File" section), you can do the same for sqlite. Since you can execute shell commands from a java application (using Runtime.getRuntime().exec() methods), and you are the "owner" (Linux user id) of the database, you should be able to run this "sqlite3 .dump" command even on a non-rooted device. I have never seen an Android device without the sqlite3 tool installed, so the command should always be available.
Moreover, since dump file is just a text file, you should be able to prepend any PRAGMA's to it that are required for compatibility (like the one you quoted).
I haven't tested any of this, but just wanted to think with you on this interesting topic.
An sqlite database is just a file so you could copy the file but I think you may have problems with permissions in android preventing you from accessing the database.
A better solution IMO would be to sync your data to an external website.
Using a combination of a custom sync adapter and the account manager with a website or web service that has a RESTfull api to receive and send the synced data would be the most reliable approach.
http://developer.android.com/training/id-auth/identify.html is a great introduction to setting up the account manager.
And for a custom sync adapter this is a great starting point.
http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/
and http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-2/
And finally an explanation of how it all fits together
https://sites.google.com/site/andsamples/concept-of-syncadapter-androidcontentabstractthreadedsyncadapter
The above approach would enable a user to switch phones and retain data at the same time and the data would always be up to date (providing you sync at the appropriate times.
It seems like a lot of work as you will need to set up a web service but it is the BEST way to make sure data is kept safe and secure and can be restored and backed up at any point.
For a web service there are lots of options available to you including cloud services such as Google docs or writing your own website. Ruby on Rails is a great solution for developing your own site as you get a full RESTfull api out of the box and it;'s dead easy to secure/lock down a rails site to authorised users only with a couple of lines of code and with Heroku you can get free hosting.
As usual with Android development the simplest of requirements actually ends up being the most difficult to implement but where data safety is paramount then it's worth the effort to do it properly.
The question is too open to answer simply because the changes that may apply to the db file content are open and one can't guarantee a specific behavior .
On the positive side sqlite project is an open source and the format of the DB file is specified Here
After taking a look there, it seems very possible/not too complicated to parse any DB file looking for Data Only and write it/dump it to another functional db file.
I believe this is the fastest and cleanest solution to the issue in hand.
so to wrap up:
Copy DB file everytime you want to back it up.
When you want to restore create a new DB using Android APIs.
Parse the data from the backed up file and write them to the newly created DB.
P.S:
regarding how to use
PRAGMA journal_mode = DELETE
Simply use db.exec("PRAGMA journal_mode = DELETE"); when creating the DB

Using Rest to store data in Sqlite

I'm creating my first android app that will make use of SQlite. I have zero experience with databases, except for creating a mysql database to use with wordpress...
Edit: After doing some research about rest, I'm still confused about how rest, sqlite, and android dev fit together. My goal is to access a rest-based web service through a url and access certain datasets, then store them in my SQlite database. Then I want to access the contents of the database through my java program, and use them accordingly.
The datasets can be downloaded individually in CSV format, but because I will be using so many of them, I don't want to go through every line individually and store them in the database. I'm hoping there's a more efficient way to store these datasets in the database.
My main questions are:
How can I copy the XML contents of a webpage from a url into my sqlite database? Can I do this with my java program, through the sqlite database, or a java library?
Do I only need to copy the contents of the webpages from the url into the sqlite database one time? If so, what can I do if any information is changed in the datasets?
You first need a schema for your sqllite DB. That schema should map to the objects behind the web service. For e.g, you need a Person table in your DB if there is a Person entity on the web. It depends on what all you want to capture.
When you are done designing the schema, you should start writing the code that help you create & manage DB on android. This is done with the help of SQLiteOpenHelper class:
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
If you need to keep the DB synce'd with the data on the cloud (web services), you should implement sync. Android provides a very efficient sync framework.
Also, do watch this video from Android engineers explaining the best practices: http://www.youtube.com/watch?v=xHXn3Kg2IQE
Note, to actually fetch the data from the web service you would use UrlConnection API:
http://developer.android.com/reference/java/net/URLConnection.html
This sample probably captures most of it.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
In terms of reading CSV files, there are some good resources here:
Can you recommend a Java library for reading (and possibly writing) CSV files?
Once you have read each CSV line into an object, then you can turn around and persist it to the database. I'm the author of ORMLite so I'll talk about using it. I don't believe there is a hibernate port for Android.
There are a number of Android examples to help you to get up to speed with ORMLite. Also some good tutorials. If you want to write a number of rows at once then I'd recommend using the batch tasks ORMLite feature. For information, see the discussion about creating lists of objects on the mailing list.
I can answer your first question about " I'm not sure how to add them efficiently"?
yes, SQlite is very powerful and intelligent, you can add thousand of records in one transaction, just like traditional database, It significantly improve performance.
about second question, as my understanding, because CVS file is very simple, so you can download and analyze it by yourself.

Categories

Resources