I am using D2R server for RDB to RDF conversion. Now I want to save this rdf into Jena TDB backed dataset while I am using D2R server. In short I want to integrate Jena TDB with D2R.
Code for RDB to RDF conversion is:
public static void main String(args[])
{
String writeLocation="C:/Users/PJH/Desktop/Destination/";
// Get the Jena Model view of the D2RQ RDF object.
Model m = new ModelD2RQ("C:/Users/PJH/desktop/d2rq-0.8.1/d2rq-0.8.1/doc/example/mapping-iswc.ttl");
//Writing into a file.
// writeLocation="C:/Users/PJH/Desktop/Destination/";
System.out.println("HIiiiiiiiiiiii");
FileManager fm = FileManager.get();
fm.addLocatorClassLoader(JenaD2RQClass.class.getClassLoader());
// m=fm.get().loadModel(fileNmaeURI);
FileOutputStream fout =new FileOutputStream(writeLocation+"D2RQCopy1234567.rdf");
m.write(fout,"TURTLE");
}
How to store this D2RQ mapped model in Jena TDB backed dataset?
ModelD2RQ allows you to query the D2RQ engine from Jena. D2R continues to store the information, because, the D2RQ-jena interface is merely an adapter for translating the stored information to triples.
Note that TDB is the storage system itself. It is unclear what you mean by "integrate Jena TDB with D2R". That is akin to saying "Integrate Oracle with MySQL". They each store data, and there is no meaningful inter-operation between the two systems actively running.
If I assume that you wish to take a snapshot of the current contents of your D2R server, and store that snapshot within TDB, then it can be quite simple to do so:
First, create a TDB Dataset with the TDB Java API, then add your ModelD2RQ to that Dataset.
final Model m = new ModelD2RQ("C:/Users/PJH/desktop/d2rq-0.8.1/d2rq-0.8.1/doc/example/mapping-iswc.ttl");
final Dataset dataset = TDBFactory.createDataset("MyDatabases/Dataset1") ;
dataset.getDefaultModel().add(m);
Related
I have a requirement to read a csv file and generate several different projections of the data from save to files. I'm using CsvProvider to read the file and then map the data into other CsvProviders which I save to disk. Currently I have seperate save functions to save each of these projections. I'm wondering if I could create a generic saveCsv function like this?
let saveCsv<'a when 'a :> CsvProvider> (csvType:'a) fileName data =
let csv = new csvType(data)
csv.Save(fileName)
I can't seem to get the type constraint correct and also how do I new up a instance of the csvtype?
D2RQ creates a RDF representation of the DB using a Jena model.
Model m = new ModelD2RQ("file:outfile2.ttl");
I know that the returned model is a "read-only" model.
Hence, if I try to add a resource to the model I get a "jena.shared.AddDeniedException" exception.
Resource r1=m.createResource("http://www.stackoverflow.com#34");
r1.addProperty(RDF.type, ...); <-throws the exception
How can I decouple the model m from the database so that I can modify it? I don't want to write the model back, I just use D2RQ to get an RDF based DB-dump which I want to process further (I know that extensions like D2RQ update enable the modification of the database by modifying the RDF graph but I don't want to modify the DB)
Thanks
Take a copy to disconnect the model from the database:
Model m = new ModelD2RQ("file:outfile2.ttl");
Model mCopy = ModelFactory.createDefaultModel() ;
mCopy.add(m) ;
mCopy.addProperty(...)
Another way is to have a union model, where the in-memory part is the first, and update-able, part of the union.
Model m = new ModelD2RQ("file:outfile2.ttl");
Model extra = ModelFactory.createDefaultModel() ;
Model m2 = ModelFactory.createUnion(exrta, m2) ;
...
I am using Gremlin and Neo4j to manipulate the ENRON dataset from infochimps. This dataset has two types of vertexes, Message and Email Addresss and two types of edges, SENT and RECEVIED_BY. I would like to create a custom index on this dataset that creates a Lucene document for each vertex of type: 'Message' and incorporates information from associated vertexes (e.g., v.in(), v.out()) as additional fields in the Lucene document.
I am thinking of code along the lines of
g = new Neo4jGraph('enron');
PerFieldAnalyzerWrapper analyzer =
new PerFieldAnalyzerWrapper(new StandardAnalyzer());
analyzer.addAnalyzer("sender", new KeywordAnalyzer());
analyzer.addAnalyzer("recipient", new KeywordAnalyzer());
IndexWriter idx = new IndexWriter (dir,analyzer,IndexWriter.MaxFieldLength.UNLIMITED);
g.V.filter{it.type == 'Message'}.each { v ->
Document doc = new Document();
doc.add(new Field("subject", v.subject));
doc.add(new Field("body", v.body));
doc.add(new Field("sender", v.in().address);
v.out().each { recipient ->
doc.add(new Field("recipient", recipient.address));
}
idx.addDocument(doc);
}
idx.close();
My questions are:
Is there a better way to enumerate vertexes for indexing?
Can I use auto-indexing for this, and if so, how to I specify what should be indexed?
Can I specify my own Analyzer, or am I stuck with the default? What is the default?
If I must create my own index, should I be using gremlin for this, or am I better off with a Java program?
I will be talking about direct Neo4j access here since I'm not well travelled in Gremlin.
So you'd like to build a Lucene index "outside of" the graph itself? Otherwise you can use the built in graphDb.index().forNodes( "myIndex", configForMyIndex ) to get (created on demand) a Lucene index associated with neo4j. You can then add multiple fields to each document by calling index.add( node, key, value ), where each node will be represented by one document in that Lucene index.
1) In Gremiln... I don't know
2) See http://docs.neo4j.org/chunked/milestone/auto-indexing.html
3) See http://docs.neo4j.org/chunked/milestone/indexing-create-advanced.html
4) Do you need to create it outside of the db entirely? If so, why?
I just finished an import with a Java process and it's really easy, in my opinion better inclusive through Gremlin.
Anyway, if the process is failing is because of you CAN'T create a new object of StandardAnalyzer. All the constructors of that class require parameters, so you should create a wrapper class or create it with the right version of Lucene like paramater in the constructor.
Neo4J, until today, accepts only until the lucene version 36.
I am trying to use Jena framework to edit an existing ontology built with Protoge 4.2. i.e. to change property values or add individuals or classes and then do reasoning. Assume in the ontology we have a rule such that: hasAge(?p,?age)^swrlb:greaterThan(?age,18)->Adult(?p). I would like to be able to change hasAge property on Jena side and see if someone is an Adult or not. Can you please provide me some sample code on this? Any help is appreciated.
Assuming that :
you know how to populate your model by reading in the ontology that you built
You have put Pellet on the classpath
You replace the IRI's below with those from your domain
You have assertions enabled
The following code snippet will add an age to an individual x-test://individual and assert that the property that would be introduced by SWIRL is satisfied.
// create an empty ontology model using Pellet spec
final OntModel model = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );
// read the file
model.read( ont );
// Grab a resource and and property, and then set the property on that individual
final Resource Adult = ResourceFactory.createResource("x-domain://Adult");
final Property hasAge = ResourceFactory.createProperty("x-domain://hasAge");
final Resource res = model.createResource("x-test://individual");
res.addLiteral(hasAge, 19);
// Test that the swirl rule has executed
assert( res.hasProperty(RDF.type, Adult) );
I'm looking for the best method for importing csv or excel file to SQL Server 2005 using .net MVC.
Thank you.
There's a really good library called FileHelpers which is a) 100% free, b) fully in C#, and it can easily import any kind of text-based file - comma-separated, tab-separated, fixed width and so on.
You should have no trouble using this to load your CSV file into in-memory objects and storing those in SQL Server using ADO.NET.
In FileHelpers, you first need to have a class that describes your data, e.g. a "Customer" class (or whatever it is you're importing).
Then, you can import a file using code something like this:
FileHelperEngine<Customer> engine = new FileHelperEngine<Customer>();
Customer[] dataLoaded = engine.ReadFile(fileName);
Once you have your array of customers, you can either just iterate through that and save the data (typically inside a transaction) with e.g. a stored procedure or a ad-hoc SQL query:
using(TransactionScope ts = new TransactionScope())
{
foreach(Customer c in dataLoadad)
{
SaveCustomer(c);
}
ts.Complete();
}
or you could convert the customer array to a DataTable and use SqlBulkCopy to bulk insert that into your SQL Server database - there are lots of options!
UPDATE:
Do you have a [DelimitedRecord] or another of those attributes on your BlackListDevice class?
Fixed this by adding a seperate class for file uploads, works like a charm using the FileHelper.