本文整理汇总了Java中com.hp.hpl.jena.reasoner.rulesys.Rule类的典型用法代码示例。如果您正苦于以下问题:Java Rule类的具体用法?Java Rule怎么用?Java Rule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Rule类属于com.hp.hpl.jena.reasoner.rulesys包,在下文中一共展示了Rule类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: inferClassRelations_OLD
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
@Deprecated
public static boolean inferClassRelations_OLD(Model classModel) {
InputStream is = AbstractNIFParser.class.getClassLoader()
.getResourceAsStream(TYPE_INFERENCE_RULES);
List<String> lines;
try {
lines = IOUtils.readLines(is);
} catch (IOException e) {
LOGGER.error("Couldn't load type inferencer rules from resource \""
+ TYPE_INFERENCE_RULES
+ "\". Working on the standard model.", e);
return false;
}
IOUtils.closeQuietly(is);
StringBuilder sb = new StringBuilder();
for (String line : lines) {
sb.append(line);
}
Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(sb
.toString()));
InfModel infModel = ModelFactory.createInfModel(reasoner, classModel);
classModel.add(infModel);
return true;
}
开发者ID:dice-group,项目名称:Cetus,代码行数:26,代码来源:ClassModelCreator.java
示例2: registerSerializers
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
/**
* @param conf
* register some Jena serialisers to this configuration
*/
public static void registerSerializers(Config conf) {
conf.registerSerialization(Node[].class, NodeSerialiser_ARRAY.class);
conf.registerSerialization(Node_URI.class, NodeSerialiser_URI.class);
conf.registerSerialization(Node_Literal.class, NodeSerialiser_Literal.class);
conf.registerSerialization(Node_Blank.class, NodeSerialiser_Blank.class);
conf.registerSerialization(Node_Variable.class, NodeSerialiser_Variable.class);
conf.registerSerialization(Triple.class, TripleSerialiser.class);
conf.registerSerialization(ArrayList.class);
conf.registerSerialization(KestrelServerSpec.class, KestrelServerSpec_Serializer.class);
conf.registerSerialization(Rule.class, RuleSerializer.class);
conf.registerSerialization(Graph.class, GraphSerialiser.class);
conf.registerSerialization(GraphMem.class, GraphSerialiser.class);
conf.registerSerialization(MultiUnion.class, GraphSerialiser.class);
conf.registerSerialization(Template.class, TemplateSerialiser.class);
conf.registerSerialization(ElementFilter.class);
// conf.registerSerialization(Node_NULL.class);
// conf.registerSerialization(Node_Blank.class);
}
开发者ID:openimaj,项目名称:openimaj,代码行数:23,代码来源:JenaStormUtils.java
示例3: createInferencer
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
public static SimpleSubClassInferencer createInferencer(Model classModel) {
String resourceName = GerbilConfiguration.getInstance().getString(SUB_CLASS_INFERENCER_RULE_FILE_KEY);
if (resourceName == null) {
LOGGER.error("Couldn't load subclass inferencer rules resource name from properties. Returning null.");
return null;
}
InputStream is = RootConfig.class.getClassLoader().getResourceAsStream(resourceName);
List<String> lines;
try {
lines = IOUtils.readLines(is);
} catch (IOException e) {
LOGGER.error("Couldn't load subclass inferencer rules from resource \"" + resourceName
+ "\". Returning null.", e);
return null;
}
IOUtils.closeQuietly(is);
StringBuilder sb = new StringBuilder();
for (String line : lines) {
sb.append(line);
}
Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(sb.toString()));
InfModel inf = ModelFactory.createInfModel(reasoner, classModel);
SimpleSubClassInferencer inferencer = new SimpleSubClassInferencer(inf);
return inferencer;
}
开发者ID:dice-group,项目名称:gerbil,代码行数:27,代码来源:SimpleSubClassInferencerFactory.java
示例4: addRules
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
public boolean addRules(List<String> rules) {
for(String f:rules)
ruleList.add(Rule.parseRule(f));
if (preBoundReasoner != null) {
reasoner = preBoundReasoner;
preBoundReasoner = null;
}
try {
if (getReasonerOnlyWhenNeeded() != null) {
getReasonerOnlyWhenNeeded().setRules(ruleList);
}
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
newInputFlag = true;
dataModelSourceCount++;
return true;
}
开发者ID:crapo,项目名称:sadlos2,代码行数:20,代码来源:JenaReasonerPlugin.java
示例5: explain
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
public List<Explanation> explain(String rulename) {
startTrace();
try {
if (getReasonerOnlyWhenNeeded() != null) {
getReasonerOnlyWhenNeeded().setDerivationLogging(true);
List<Rule> rules = getReasonerOnlyWhenNeeded().getRules();
for (int i = 0; i < rules.size(); i++) {
String ruleName = rules.get(i).getName();
if (ruleName != null && ruleName.equals(rulename)) {
return explainRule(rules.get(i), null);
}
}
List<Explanation> explanations = new ArrayList<Explanation>();
Explanation expl = new Explanation(null, "Failed to get explanation for rule '" + rulename + "'. Rule not in loaded rule set.");
explanations.add(expl);
endTrace();
return explanations;
}
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
开发者ID:crapo,项目名称:sadlos2,代码行数:25,代码来源:JenaReasonerPlugin.java
示例6: setUp
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// We are going to load mapping and rules files.
Model mapModel = FileManager.get().loadModel("./mapping.ttl");
this.instances = new ModelD2RQ(mapModel, "http://www.morelab.deusto.es/ontologies/sorelcom#");
this.myReasoner = new GenericRuleReasoner(Rule.rulesFromURL("file:./rules.txt"));
this.myReasoner.setDerivationLogging(true);
}
开发者ID:aitoralmeida,项目名称:c4a_data_repository,代码行数:9,代码来源:RuleEngineTest.java
示例7: testValidRulesFile
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
/**
* Test if rules are properly loaded
*
*/
@Test
public void testValidRulesFile() throws Exception {
boolean res = false;
// We are going to load rules from file
List<Rule> listOfRules = Rule.rulesFromURL("file:./rules.txt");
if (listOfRules.size() > 0) {
// There are rules loaded into the list, so the file contains valid rules
res = true;
}
assertTrue(res);
}
开发者ID:aitoralmeida,项目名称:c4a_data_repository,代码行数:16,代码来源:RuleEngineTest.java
示例8: bindJenaRuleReasoner
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
private static void bindJenaRuleReasoner() {
final String rule = "[gmailFriend: (?person <http://xmlns.com/foaf/0.1/mbox_sha1sum> ?email), strConcat(?email, ?lit), regex(?lit, '(.*gmail.com)')"
+ "-> (?person " + RDF_TYPE_INSPARQL + " <http://www.people.com#GmailPerson>)]";
Reasoner ruleReasoner = new GenericRuleReasoner(Rule.parseRules(rule));
ruleReasoner = ruleReasoner.bindSchema(schema);
inferredModel = ModelFactory.createInfModel(ruleReasoner, friendsModel);
}
开发者ID:zhoujiagen,项目名称:Jena-Based-Semantic-Web-Tutorial,代码行数:8,代码来源:HelloSemanticWeb.java
示例9: loadRules
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
public boolean loadRules(URI ruleFileName) throws IOException {
if (ruleFileName != null) {
ruleList.addAll(Rule.rulesFromURL(ruleFileName.toString()));
newInputFlag = true;
dataModelSourceCount++;
return true;
}
//TODO this needs to handle the case where there are no rules
else
return false;
}
开发者ID:crapo,项目名称:sadlos2,代码行数:12,代码来源:JenaReasonerPlugin.java
示例10: deleteRule
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
public boolean deleteRule(String ruleName) throws RuleNotFoundException {
try {
getReasonerOnlyWhenNeeded();
} catch (ConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
for (int i=0; i<ruleList.size();i++){
Rule r = ruleList.get(i);
String rName = new String(r.getName());
if(rName.equals(ruleName)){
ruleList.remove(r);
if (preBoundReasoner != null) {
reasoner = preBoundReasoner;
preBoundReasoner = null;
}
try {
if (getReasonerOnlyWhenNeeded() != null) {
getReasonerOnlyWhenNeeded().setRules(ruleList);
}
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
newInputFlag = true;
return true;
}
}
dataModelSourceCount++;
return false;
}
开发者ID:crapo,项目名称:sadlos2,代码行数:32,代码来源:JenaReasonerPlugin.java
示例11: processRuleQuery
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
protected ResultSet processRuleQuery(com.hp.hpl.jena.reasoner.rulesys.Rule rule, List<String> premisesAsStrings, String q) throws QueryParseException, QueryCancelledException {
logger.debug("Explanation executing query: " + q);
ResultSet rs = ask(q);
if (rs != null) {
int numResults = rs.getRowCount();
String[] headers = rs.getColumnNames();
String headerStr = " ";
for (int hi = 0; hi < headers.length; hi++) {
if (hi > 0) headerStr += ", ";
headerStr += "?" + headers[hi].toString();
}
for (int row = 0; row < numResults; row++) {
String rowStr = " ";
for (int col = 0; col < rs.getColumnCount(); col++) {
if (col > 0) rowStr += ", ";
Object o = rs.getResultAt(row, col);
if (o instanceof com.hp.hpl.jena.graph.Node) {
rowStr += nodeShortString((com.hp.hpl.jena.graph.Node)o);
}
else if (o instanceof String && ((String)o).indexOf('#') > 0) {
rowStr += ((String)o).substring(((String)o).indexOf('#') + 1);
}
else {
rowStr += o.toString();
}
}
}
}
return rs;
}
开发者ID:crapo,项目名称:sadlos2,代码行数:31,代码来源:JenaReasonerPlugin.java
示例12: writeRules
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
private boolean writeRules(OntModel ontModel, String modelName) throws ConfigurationException, IOException {
ConfigurationManagerForEditing cmgr = getConfigurationMgr();
String altUrl = cmgr.getAltUrlFromPublicUri(modelName);
String rulefn = altUrl.substring(0, altUrl.lastIndexOf(".")) + ".rules";
SadlUtils su = new SadlUtils();
File ruleFile = new File(su.fileUrlToFileName(rulefn));
List<Rule> rules = editedRules.get(modelName);
StringBuilder contents = new StringBuilder();
contents.append("# Jena Rules file generated by SadlServerPE.\n");
StringBuilder ruleContent = new StringBuilder();
for (int i = 0; i < rules.size(); i++) {
Rule rule = rules.get(i);
ruleContent.append(rule.toString());
ruleContent.append("\n");
}
// We will assume for the moment that there are no prefixes but that all names are the FQName
contents.append("\n");
// Because rule files are loaded for each sub-model, there is no need to put in includes
if (ruleContent.length() > 0) {
contents.append(ruleContent);
}
su.stringToFile(ruleFile, contents.toString(), false);
return true;
}
开发者ID:crapo,项目名称:sadlos2,代码行数:30,代码来源:SadlServerPEImpl.java
示例13: processRuleQuery
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
protected ResultSet processRuleQuery(com.hp.hpl.jena.reasoner.rulesys.Rule rule, List<String> premisesAsStrings, String q) throws QueryParseException, QueryCancelledException, InvalidNameException, ConfigurationException {
logger.debug("Explanation executing query: " + q);
q = prepareQuery(q);
ResultSet rs = ask(q);
if (rs != null) {
int numResults = rs.getRowCount();
String[] headers = rs.getColumnNames();
String headerStr = " ";
for (int hi = 0; hi < headers.length; hi++) {
if (hi > 0) headerStr += ", ";
headerStr += "?" + headers[hi].toString();
}
for (int row = 0; row < numResults; row++) {
String rowStr = " ";
for (int col = 0; col < rs.getColumnCount(); col++) {
if (col > 0) rowStr += ", ";
Object o = rs.getResultAt(row, col);
if (o instanceof com.hp.hpl.jena.graph.Node) {
rowStr += nodeShortString((com.hp.hpl.jena.graph.Node)o);
}
else if (o instanceof String && ((String)o).indexOf('#') > 0) {
rowStr += ((String)o).substring(((String)o).indexOf('#') + 1);
}
else {
rowStr += o.toString();
}
}
}
}
return rs;
}
开发者ID:crapo,项目名称:sadlos2,代码行数:32,代码来源:JenaReasonerPlugin.java
示例14: runInference
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
private Model runInference(Model data, URL rules, int lineLength, int maxLineLength) throws IOException
{
Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL(rules.toString()));
InfModel inf = ModelFactory.createInfModel(reasoner, data);
// Break long literals (more than lineLength chars) using carriage returns
Model remove = ModelFactory.createDefaultModel();
Model add = ModelFactory.createDefaultModel();
Selector sel = new SimpleSelector(null, null, (String)null);
for(StmtIterator sIt = inf.listStatements(sel); sIt.hasNext();)
{
Statement s = sIt.nextStatement();
if(!s.getObject().isLiteral())
continue;
String l = s.getString();
String lp = paginate(l, lineLength, maxLineLength);
if (lp.length() != l.length())
{
remove.add(s);
add.add(s.getSubject(), s.getPredicate(), lp, s.getLanguage());
}
}
inf.remove(remove);
inf.add(add);
return inf;
}
开发者ID:rhizomik,项目名称:redefer-rdf2svg,代码行数:30,代码来源:RenderRDF.java
示例15: addRules
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
public static List<Rule> addRules( List<Rule> result, Assembler a, Resource root )
{
addLiteralRules( root, result );
addIndirectRules( a, root, result );
addExternalRules( root, result );
return result;
}
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:8,代码来源:RuleSetAssembler.java
示例16: addIndirectRules
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
static private void addIndirectRules( Assembler a, Resource root, List<Rule> result )
{
StmtIterator it = root.listProperties( JA.rules );
while (it.hasNext())
{
Resource r = getResource( it.nextStatement() );
result.addAll( ((RuleSet) a.open( r )).getRules() );
}
}
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:10,代码来源:RuleSetAssembler.java
示例17: addExternalRules
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
static private void addExternalRules( Resource root, List<Rule> result )
{
StmtIterator it = root.listProperties( JA.rulesFrom );
while (it.hasNext())
{
Resource s = getResource( it.nextStatement() );
result.addAll( Rule.rulesFromURL( s.getURI() ) );
}
}
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:10,代码来源:RuleSetAssembler.java
示例18: addLiteralRules
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
static private void addLiteralRules( Resource root, List<Rule> result )
{
StmtIterator it = root.listProperties( JA.rule );
while (it.hasNext())
{
String s = getString( it.nextStatement() );
result.addAll( Rule.parseRules( s ) );
}
}
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:10,代码来源:RuleSetAssembler.java
示例19: getRule
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
/**
* Return the rule associated with this environment, null if no such rule.
*/
public Rule getRule() {
if (clause != null) {
return clause.rule;
} else {
return null;
}
}
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:11,代码来源:EnvironmentFrame.java
示例20: add
import com.hp.hpl.jena.reasoner.rulesys.Rule; //导入依赖的package包/类
/**
* Record a request for a rule firing. For monotonic rulesets it may be
* actioned immediately, otherwise it will be stacked up.
*/
public void add(Rule rule, BindingEnvironment env, boolean isAdd) {
if (isMonotonic) {
RETERuleContext context = new RETERuleContext((ForwardRuleInfGraphI)gcontext.getGraph(), gcontext.getEngine());
context.setEnv(env);
context.setRule(rule);
execute(context, isAdd);
} else {
// Add to the conflict set, compressing +/- pairs
boolean done = false;
if ( (isAdd && nNeg > 0) || (!isAdd && nPos > 0) ) {
for (Iterator<CSEntry> i = conflictSet.iterator(); i.hasNext(); ) {
CSEntry cse = i.next();
if (cse.rule != rule) continue;
if (cse.env.equals(env)) {
if (isAdd != cse.isAdd) {
i.remove();
if (cse.isAdd) nPos--; else nNeg --;
done = true;
} else {
// Redundant insert? Probably leave in for side-effect cases like print
}
}
}
}
if (!done) {
conflictSet.add(new CSEntry(rule, env, isAdd));
if (isAdd) nPos++; else nNeg++;
}
}
}
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:35,代码来源:RETEConflictSet.java
注:本文中的com.hp.hpl.jena.reasoner.rulesys.Rule类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论