You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Ankit Verma <an...@impetus.co.in> on 2011/12/23 08:01:37 UTC

Regarding jena

Hi Andy,

Can u pls help me in creating a new web application from scratch.
Secondly i am trying to import wordnet model but facing some error can u pls see
the below error.

the code which i am using is
package test;

import java.io.*;
import com.hp.hpl.jena.db.*;
import com.hp.hpl.jena.rdf.model.*;

/**
* Creates a model in the MySQL database, and loads the 3 WordNet RDF graphs
* into it. This could also be accomplished on the commandline via
* jena.dbcreate and jena.dbload.
*/
public class ImportWordnet {

/** MySQL driver classname */
private static final String mysqlDriver = "com.mysql.jdbc.Driver";

/** URL of database to use */
private static final String DB_URL = "jdbc:mysql://localhost/test";
private static final String DB_TYPE = "MySQL";

/** User credentials */
private static final String DB_USER = "root";
private static final String DB_PASSWORD = "";

/** Name of the Jena model to create */
private static final String MODEL_NAME = "wordnet";

/** Locations of wordnet graphs to load */
private static String WN_NOUNS = "wordnet_nouns-20010201.rdf";
private static String WN_GLOSSARY = "wordnet_glossary-20010201.rdf";
private static String WN_HYPONYMS = "wordnet_hyponyms-20010201.rdf";

/**
* Creates a MySQL backed model and reads the wordnet RDF files into it
*/
public static void main(String args[]) {

try {
// Instantiate database driver
Class.forName(mysqlDriver);
} catch (ClassNotFoundException e) {
System.err.println("MySQL driver class not found");
System.exit(-1);
}

// Get a connection to the db
DBConnection connection = new DBConnection(DB_URL, DB_USER, DB_PASSWORD,
DB_TYPE);

// Get a ModelMaker for database-backed models
ModelMaker maker = ModelFactory.createModelRDBMaker(connection);

// Create a new model named "wordnet".
Model wordnetModel = maker.createModel(MODEL_NAME,true);

try {

// Importing models inside a transaction helps performance.
// Without this, the model each statement is auto-committed as it is
// added.
wordnetModel.begin();

// Read each of the three WordNet documents into the model
//readFileIntoModel(WN_NOUNS, wordnetModel);
readFileIntoModel(WN_GLOSSARY, wordnetModel);
//readFileIntoModel(WN_HYPONYMS, wordnetModel);

// Commit the transaction
wordnetModel.commit();

} catch (FileNotFoundException e) {

System.err.println(e.toString());
} finally {

try {
// Close the database connection
connection.close();
} catch (java.sql.SQLException e) {}
}
}

/**
* Reads RDF from a file into a model
* @param filename Name of the RDF file to read
* @param model The model to read the RDF into
* @throws FileNotFoundException if the file can't be located on the classpath
*/
private static void readFileIntoModel(String filename, Model model)
throws FileNotFoundException {

// Use the class loader to find the input file
InputStream in =
ImportWordnet.class.getClassLoader().getResourceAsStream(filename);

if (in == null) {
throw new FileNotFoundException("File not found on classpath: "+
filename);
}

// Read the triples from the file into the model
model.read(in,null);
}
}

and the error is

"java.io.FileNotFoundException: File not found on classpath:
wordnet_glossary-20010201.rdf"




Thanks and Regards
Ankit Verma
Associate Software Engineer
Impetus Infotech (India) Pvt. Ltd.
Phone: + 91-120.409.2200 x 2773
www.impetus.com<http://www.impetus.com/> <http://www.impetus.com/>



________________________________

New Impetus webcast on-demand 'Big Data Technologies for Social Media Analytics' available at http://bit.ly/nFdet0.

Visit http://www.impetus.com to know more. Follow us on www.twitter.com/impetuscalling


NOTE: This message may contain information that is confidential, proprietary, privileged or otherwise protected by law. The message is intended solely for the named addressee. If received in error, please destroy and notify the sender. Any use of this email is prohibited when received in error. Impetus does not represent, warrant and/or guarantee, that the integrity of this communication has been maintained nor that the communication is free of errors, virus, interception or interference.

Re: Regarding jena

Posted by Andy Seaborne <an...@apache.org>.
On 23/12/11 07:01, Ankit Verma wrote:
>
> Hi Andy,
>
> Can u pls help me in creating a new web application from scratch.
> Secondly i am trying to import wordnet model but facing some error can u pls see
> the below error.

Your error is:

 > "java.io.FileNotFoundException: File not found on classpath:
 > wordnet_glossary-20010201.rdf"



>
> the code which i am using is
> package test;
>
> import java.io.*;
> import com.hp.hpl.jena.db.*;

This is deprecated.  It has been removed from jena 2.7.0.  Use TDB if 
you need to use a database at all.  SDB is also a possibility.

> import com.hp.hpl.jena.rdf.model.*;

> readFileIntoModel(WN_GLOSSARY, wordnetModel);

> private static void readFileIntoModel(String filename, Model model)
> throws FileNotFoundException {
>
> // Use the class loader to find the input file
> InputStream in =
> ImportWordnet.class.getClassLoader().getResourceAsStream(filename);
>
> if (in == null) {
> throw new FileNotFoundException("File not found on classpath: "+
> filename);
> }

Did you put the file on the classpath?  It appears not.

Why not simply read it from the filing system?

     FileManager.get().readModel(model, filename) ;



Andy