我使用jena为电子邮件存储创建了一个rdf模型。我的thr rdf的代码是:
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());
我已将整数的MAIL_SIZE转换为字符串,以将其存储为rdf的属性。现在我想根据邮件大小执行范围查询:
SELECT ?resource
WHERE
{
?resource <MAIL_SIZE:> ?size .
FILTER (?size >= 24)
}
但是这个查询给出了错误...我知道这是因为我将MAIL_SIZE存储为属性,但我不知道如何做到这一点?纠正我,如果我错了,我真的很擅长这个事情吗? 的编辑: PS:我创建了自己的一组属性。
//定义制作电子邮件的rdf所需的所有属性
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:" );
}
这是我查询rdf模型的代码。在这里我从命令行接受输入但是字符串的查询也有效...
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.
}
}
这表明查询有效:
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>> |
答案 0 :(得分:0)
我问了一个我觉得非常相关的问题,关于如何使用Jena而不是字符串整数,以便我可以查询和过滤这些整数。我得到了一个有用的答案,我认为它对你也很有用。
Adding age (integer literals) to Jena RDF triples, and querying on them with SPARQL