I have created a rdf model using jena for email storage..My code for thr rdf is :
Resource mail= model.createResource(msg.getMessageID())
.addProperty(EMAILRDF.SUBJECT, subjec)
.addProperty(EMAILRDF.TO,receiveraddr)
.addProperty(EMAILRDF.FROM,senderaddr)
.addProperty(EMAILRDF.REC_NAME,receivername)
.addProperty(EMAILRDF.SEND_NAME,sendername)
.addProperty(EMAILRDF.ENCODING,encod)
.addProperty(EMAILRDF.CONTENT,cont)
.addProperty(EMAILRDF.DATE,dat)
.addProperty(EMAILRDF.FOLDER_NAME,foldername)
.addProperty(EMAILRDF.UID,uid)
.addProperty(EMAILRDF.IN_REPLYTO,replyto)
.addProperty(EMAILRDF.IN_REPLYTONAME,replyname)
.addProperty(EMAILRDF.CC,cc)
.addProperty(EMAILRDF.BCC,bcc)
.addProperty(EMAILRDF.MAIL_SIZE,msize) //here
.addProperty(EMAILRDF.ATTACHEMENT_NAME,filename)
.addProperty(EMAILRDF.ATTACHEMENT_NO,nos)
.addProperty(EMAILRDF.CONTENT_TYPE,msg.getContentType());
I have converted the MAIL_SIZE which is in integer to string to store it as a property of the rdf .Now I want to perform range queries based on the mail size :
SELECT ?resource
WHERE
{
?resource <MAIL_SIZE:> ?size .
FILTER (?size >= 24)
}
but this query gives error ...I know that its due to the fact that I stored the MAIL_SIZE as property but I don't know how to do this ? Correct me if I am wrong I am really new to this thing ? EDITS: PS: I have created my own set of properties.
//To define all the properties needed to make the rdf of the email
package email;
import com.hp.hpl.jena.rdf.model.*;
public class EMAILRDF {
//Create a default model
private static Model m = ModelFactory.createDefaultModel();
//Subject of the mail
public static final Property SUBJECT = m.createProperty("SUB:" );
//Sender of the mail
public static final Property FROM = m.createProperty("FROM:" );
//Receiver of the mail
public static final Property TO = m.createProperty("TO:" );
//Return path
public static final Property RETURN_PATH = m.createProperty("RETURNPATH:" );
//main contents of the mail
public static final Property CONTENT = m.createProperty("CONTENT:" );
//format of the mail
public static final Property FORMAT = m.createProperty("FORMAT:" );
//content type like html etc
public static final Property CONTENT_TYPE = m.createProperty("CONTENTTYPE:" );
//encoding in bits
public static final Property ENCODING = m.createProperty("ENCODING:" );
//date of the email
public static final Property DATE = m.createProperty("DATE:" );
//CC of email
public static final Property CC = m.createProperty("CC:" );
//BCC of email
public static final Property BCC = m.createProperty("BCC:" );
//NAME OF THE SENDER
public static final Property ATTACHEMENT_NAME = m.createProperty("ATTACHEMENTNAME:" );
public static final Property ATTACHEMENT_NO = m.createProperty("ATTACHEMENTNO:" );
//SIZE OF MAIL
public static final Property MAIL_SIZE = m.createProperty("MAILSIZE:" );
//SIZE OF THE ATTACHEMENT of email
public static final Property ATTACHEMENT_SIZE = m.createProperty("ATTACHEMENTSIZE:" );
//MAIL TO WHICH PARTICULAR MAIL HAVE REPLIED
public static final Property IN_REPLYTO = m.createProperty("REPLIEDTO:" );
public static final Property IN_REPLYTONAME = m.createProperty("REPLIEDTONAME:" );
//FOLDER IN WHICH email EXISTS
public static final Property FOLDER_NAME = m.createProperty("FOLDERNAME:" );
//UID of email
public static final Property UID = m.createProperty("UID:" );
//name os receiver of email
public static final Property REC_NAME = m.createProperty("RECIEVERS_NAME:" );
//name of sender of email
public static final Property SEND_NAME = m.createProperty("SENDER_N AME:" );
}
This is my code for querying the rdf model . In this I am taking input from command line but yeah string s query also works...
public class test4query extends Object {
public static void main (String args[]) {
String s;
//load the dataset
//String query1;
//query1="hjcooljohny75@gmail.com";
//query1 = (String)(subjectentry.getText());
// String s="SELECT ?x WHERE { ?x <TO:> '"+query1+"'}";
String directory = "MYDATABASES/DATA2" ;
Dataset ds = TDBFactory.createDataset(directory) ;
Model model = ds.getDefaultModel() ;
ds.begin(ReadWrite.READ) ;
Scanner in = new Scanner(System.in);
System.out.println("Enter a string");
s = in.nextLine();
//executeCmd(s) ;
//UpdateAction.parseExecute(s,model);
Query q =QueryFactory.create(s);
QueryExecution qExec = QueryExecutionFactory.create(s, ds) ;
//ResultSet rs = qExec.execSelect() ;
QueryExecUtils.executeQuery(q, qExec) ;
// try {
// ResultSetFormatter.out(rs) ;
// } finally { qExec.close() ; }
// Another query - same view of the data.
}
}
and this shows the query working :
Enter a string
SELECT ?x WHERE { ?x <TO:> "hjcooljohny75@gmail.com" }
----------------------------------------------------------------------------------------
| x |
========================================================================================
| <<SEMA-CR-3-4MHV9RJ@bounce.oracle-mail.com>> |
| <<20140526171614.1F2D61314F66@elabs10.com>> |
| <<5833594959587942@mjinn.com>> |
| <<5x6p1e.hvnsvp7fhgxyo04mt@mail.payback.in>> |
I asked a question that I feel is very related, on how to use integers with Jena instead of strings so that I could query and filter on these integers. I got a helpful answer and I think it could be useful to you as well.
Adding age (integer literals) to Jena RDF triples, and querying on them with SPARQL
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.