我使用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());
SELECT ?resource
WHERE
{
?resource <MAIL_SIZE:> ?size .
FILTER (?size >= 24)
}
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>> |
我问了一个我觉得很相关的问题,关于如何将整数与Jena一起使用,而不是字符串,这样我就可以对这些整数进行查询和筛选。我得到了一个有用的答案,我想这对你也是有用的。
向Jena RDF三元组添加年龄(整数文字),并使用SPARQL查询它们
可以对模型的查询和写入操作进行封装,例如: <?php namespace app\index\model; use think\Model; class User extends Model { public function scopeThinkphp($query) { $query->where('name','thinkphp')->field('i
MySQL 提供了 BETWEEN AND 关键字,用来判断字段的数值是否在指定范围内。 BETWEEN AND 需要两个参数,即范围的起始值和终止值。如果字段值在指定的范围内,则这些记录被返回。如果不在指定范围内,则不会被返回。 使用 BETWEEN AND 的基本语法格式如下: [NOT] BETWEEN 取值1 AND 取值2 其中: NOT:可选参数,表示指定范围之外的值。如果字段值不满
问题内容: 如何在SQLite中高效地执行简单范围查询? 说,我有保存个人信息的数据,我想找到年龄在20到45岁之间,体重在50到80公斤之间的人? 我应该怎么做(例如设置某些索引?)以提高搜索效率? 问题答案: 我会尝试像 对“年龄”和“体重”字段建立索引将有助于加快查询速度。 这是有关在SQLite中建立索引的很好的概述:http : //www.tutorialspoint.com/sqli
问题内容: java中是否有一种优雅的方法来检查int是否等于或大于或小于1。 例如,如果我检查周围。我想在上返回true ,因为4和6距5仅1。 有内置功能可以做到这一点吗?还是我最好这样写? 当然,以上代码很难看懂。那有更好的方法吗? 问题答案: 找到它们之间的绝对差异 基于@GregS关于溢出的评论,如果您给出的差值不能适合整数,您将获得一个溢出值 通过将其中一个参数强制转换为long 将返
问题内容: 我想查询日期范围内的elasticsearch文档。我现在有两个选择,两个都适合我。已经测试了他们两个。1.范围查询2.范围过滤器 由于我现在的数据集很小,因此无法测试它们的性能。两者有什么区别?哪个会导致更快地检索文档和更快地响应? 问题答案: 查询和过滤器之间的主要区别在于评分。查询将返回每个文档具有相对排名得分的文档。过滤器没有。这种差异使过滤器更快,有两个原因。首先,它不会产生
我想查询日期范围内的elasticsearch文档。我现在有两个选择,都很适合我。我已经测试了他们两个。1.范围查询2。距离滤波器 因为我现在有一个小数据集,所以无法测试它们的性能。这两者有什么区别?哪一种方法可以更快地检索文档和响应?