当前位置: 首页>>代码示例>>Java>>正文


Java BuiltinException类代码示例

本文整理汇总了Java中com.hp.hpl.jena.reasoner.rulesys.BuiltinException的典型用法代码示例。如果您正苦于以下问题:Java BuiltinException类的具体用法?Java BuiltinException怎么用?Java BuiltinException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BuiltinException类属于com.hp.hpl.jena.reasoner.rulesys包,在下文中一共展示了BuiltinException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: averageOfList

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
private double averageOfList(Node lst, RuleContext context) {
	java.util.List<Node> l = Util.convertList(lst, context);
	int cnt = 0;
	double sum = 0;
	for (int i = 0; l != null && i < l.size(); i++) {
		Node elt = (Node) l.get(i);
        if (elt != null && elt.isLiteral()) {
        	Object v1 = elt.getLiteralValue();
        	if (v1 instanceof Number) {
        		sum += ((Number) v1).doubleValue();
        		cnt++;
         	}
        	else {
        		throw new BuiltinException(this, context, "Element of list input to max not a number: " + v1.toString());
        	}
        }
        else {
       		throw new BuiltinException(this, context, "Element of list input to max not a Literal: " + elt.toString());
        }
	}
	if (cnt < 1) {
		throw new BuiltinException(this, context, "Can't average an empty List!");
	}
    return sum / cnt;
}
 
开发者ID:crapo,项目名称:sadlos2,代码行数:26,代码来源:Average.java

示例2: headAction

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
/**
 * This method is invoked when the builtin is called in a rule head.
 * Such a use is only valid in a forward rule.
 * @param args the array of argument values for the builtin, this is an array 
 * of Nodes.
 * @param length the length of the argument list, may be less than the length of the args array
 * for some rule engines
 * @param context an execution context giving access to other relevant data
 */
@Override
public void headAction(Node[] args, int length, RuleContext context) {
    boolean ok = false;
    InfGraph inf = context.getGraph();
    Graph raw = inf.getRawGraph();
    Graph deductions = inf.getDeductionsGraph();
    for (int i = 0; i < length; i++) {
        Node clauseN = getArg(i, args, context);
        if (Util.isNumeric(clauseN)) {
            int clauseIndex = Util.getIntValue(clauseN);
            Object clause = context.getRule().getBodyElement(clauseIndex);
            if (clause instanceof TriplePattern) {
                Triple t = context.getEnv().instantiate((TriplePattern)clause);
                raw.delete(t);
                deductions.delete(t);
            } else {
                throw new BuiltinException(this, context, "illegal triple to remove non-triple clause");
            }
        } else {
            throw new BuiltinException(this, context, "illegal arg to remove (" + clauseN + "), must be an integer");
        }
    }
}
 
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:33,代码来源:Drop.java

示例3: bodyCall

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
/**
 * This method is invoked when the builtin is called in a rule body.
 * @param args the array of argument values for the builtin, this is an array 
 * of Nodes, some of which may be Node_RuleVariables.
 * @param length the length of the argument list, may be less than the length of the args array
 * for some rule engines
 * @param context an execution context giving access to other relevant data
 * @return return true if the buildin predicate is deemed to have succeeded in
 * the current environment
 */
@Override
public boolean bodyCall(Node[] args, int length, RuleContext context) {
    if (length < 2) 
        throw new BuiltinException(this, context, "Must have at least 2 arguments to " + getName());
    String text = getString( getArg(0, args, context), context );
    String pattern = getString( getArg(1, args, context), context );
    Matcher m = Pattern.compile(pattern).matcher(text);
    if ( ! m.matches()) return false;
    if (length > 2) {
        // bind any capture groups
        BindingEnvironment env = context.getEnv();
        for (int i = 0; i < Math.min(length-2, m.groupCount()); i++) {
            String gm = m.group(i+1);
            Node match =  (gm != null) ? Node.createLiteral( gm ) : Node.createLiteral("");
            if ( !env.bind(args[i+2], match) ) return false;
        }
    }
    return true;
}
 
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:30,代码来源:Regex.java

示例4: bodyCall

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
public boolean bodyCall(Node[] args, int length, RuleContext context)
{
       if (length < 2 || length > 2) 
           throw new BuiltinException(this, context, "Must have 2 arguments to " + getName());
       String str = lex(getArg(0, args, context), context);
       
       return (str.indexOf(lex(getArg(1, args, context), context)) >= 0);
   }
 
开发者ID:rhizomik,项目名称:redefer-rdf2svg,代码行数:9,代码来源:StrContains.java

示例5: lex

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
protected String lex(Node n, RuleContext context) 
{
    if (n.isBlank()) {
        return n.getBlankNodeLabel();
    } else if (n.isURI()) {
        return n.getURI();
    } else if (n.isLiteral()) {
        return n.getLiteralLexicalForm();
    } else {
        throw new BuiltinException(this, context, "Illegal node type: " + n);
    }
}
 
开发者ID:rhizomik,项目名称:redefer-rdf2svg,代码行数:13,代码来源:StrContains.java

示例6: bodyCall

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
public boolean bodyCall(Node[] args, int length, RuleContext context)
{
       if (length < 2 || length > 2) 
           throw new BuiltinException(this, context, "Must have 2 arguments to " + getName());
       String str = lex(getArg(0, args, context), context);
       
       return (str.indexOf(lex(getArg(1, args, context), context)) < 0);
   }
 
开发者ID:rhizomik,项目名称:redefer-rdf2svg,代码行数:9,代码来源:StrNotContains.java

示例7: bodyCall

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
/**
 * This method is invoked when the builtin is called in a rule body.
 * @param args the array of argument values for the builtin, this is an array 
 * of Nodes, some of which may be Node_RuleVariables.
 * @param length the length of the argument list, may be less than the length of the args array
 * for some rule engines
 * @param context an execution context giving access to other relevant data
 * @return return true if the buildin predicate is deemed to have succeeded in
 * the current environment
 */
@Override
public boolean bodyCall(Node[] args, int length, RuleContext context) {
    if (length < 1) 
        throw new BuiltinException(this, context, "Must have at least 1 argument to " + getName());
    StringBuffer buff = new StringBuffer();
    for (int i = 0; i < length-1; i++) {
        buff.append( lex(getArg(i, args, context), context) );
    }
    Node result = Node.createURI( buff.toString() );
    return context.getEnv().bind(args[length-1], result);
}
 
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:22,代码来源:UriConcat.java

示例8: bodyCall

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
/**
 * This method is invoked when the builtin is called in a rule body.
 * @param args the array of argument values for the builtin, this is an array 
 * of Nodes, some of which may be Node_RuleVariables.
 * @param length the length of the argument list, may be less than the length of the args array
 * for some rule engines
 * @param context an execution context giving access to other relevant data
 * @return return true if the buildin predicate is deemed to have succeeded in
 * the current environment
 */
@Override
public boolean bodyCall(Node[] args, int length, RuleContext context) {
    if (length < 1) 
        throw new BuiltinException(this, context, "Must have at least 1 argument to " + getName());
    StringBuffer buff = new StringBuffer();
    for (int i = 0; i < length-1; i++) {
        buff.append( lex(getArg(i, args, context), context) );
    }
    Node result = Node.createLiteral(buff.toString());
    return context.getEnv().bind(args[length-1], result);
}
 
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:22,代码来源:StrConcat.java

示例9: lex

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
/**
 * Return the appropriate lexical form of a node
 */
protected String lex(Node n, RuleContext context) {
    if (n.isBlank()) {
        return n.getBlankNodeLabel();
    } else if (n.isURI()) {
        return n.getURI();
    } else if (n.isLiteral()) {
        return n.getLiteralLexicalForm();
    } else {
        throw new BuiltinException(this, context, "Illegal node type: " + n);
    }
}
 
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:15,代码来源:StrConcat.java

示例10: getString

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
/**
 * Return the lexical form of a literal node, error for other node types
 */
protected String getString(Node n, RuleContext context) {
    if (n.isLiteral()) {
        return n.getLiteralLexicalForm();
    } else {
        throw new BuiltinException(this, context, getName() + " takes only literal arguments");
    }
}
 
开发者ID:jacekkopecky,项目名称:parkjam,代码行数:11,代码来源:Regex.java

示例11: bodyCall

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
/**
* This extends the Jena GreaterThan built-in to compare string literals and URIs
*/
  @Override
  public boolean bodyCall(Node[] args, int length, RuleContext context) {
      if (length > 3 || length < 2) {
          throw new BuiltinException(this, context, "builtin " + getName() + " requires 2 or 3 arguments but saw " + length);
      }
      Node n1 = getArg(0, args, context);
      Node n2 = getArg(1, args, context);

      boolean retVal;
      
      if (Util.comparable(n1, n2)) {
      	retVal = super.bodyCall(args, length, context);
  	}
      else {
      	String n1str;
      	String n2str;
      	if (n1.isURI()) {
      		n1str = n1.getURI();
      	}
      	else if (n1.isLiteral()) {
      		n1str = n1.getLiteralValue().toString();
      	}
      	else {
      		n1str = n1.toString();
      	}
      	if (n2.isURI()) {
      		n2str = n2.getURI();
      	}
      	else if (n2.isLiteral()) {
      		n2str = n2.getLiteralValue().toString();
      	}
      	else {
      		n2str = n2.toString();
      	}
      	retVal = (n1str.compareTo(n2str) < 0);
  	}
       
      if (length == 2) {
      	return retVal;
      }
      else {
      	 Node booleanVal =  NodeFactory.createLiteral(LiteralLabelFactory.create(new Boolean(retVal)));
           return context.getEnv().bind(args[length - 1], booleanVal);
      }
  }
 
开发者ID:crapo,项目名称:sadlos2,代码行数:49,代码来源:LessThan.java

示例12: bodyCall

import com.hp.hpl.jena.reasoner.rulesys.BuiltinException; //导入依赖的package包/类
/**
* This extends the Jena GreaterThan built-in to compare string literals and URIs
*/
  @Override
  public boolean bodyCall(Node[] args, int length, RuleContext context) {
      if (length > 3 || length < 2) {
          throw new BuiltinException(this, context, "builtin " + getName() + " requires 2 or 3 arguments but saw " + length);
      }
      Node n1 = getArg(0, args, context);
      Node n2 = getArg(1, args, context);

      boolean retVal;
      
      if (Util.comparable(n1, n2)) {
      	retVal = super.bodyCall(args, length, context);
   	}
      else {
      	String n1str;
      	String n2str;
      	if (n1.isURI()) {
      		n1str = n1.getURI();
      	}
      	else if (n1.isLiteral()) {
      		n1str = n1.getLiteralValue().toString();
      	}
      	else {
      		n1str = n1.toString();
      	}
      	if (n2.isURI()) {
      		n2str = n2.getURI();
      	}
      	else if (n2.isLiteral()) {
      		n2str = n2.getLiteralValue().toString();
      	}
      	else {
      		n2str = n2.toString();
      	}
      	retVal =  (n1str.compareTo(n2str) > 0);
  	}
      if (length == 2) {
      	return retVal;
      }
      else {
      	 Node booleanVal =  NodeFactory.createLiteral(LiteralLabelFactory.create(new Boolean(retVal)));
           return context.getEnv().bind(args[length - 1], booleanVal);
      }
  }
 
开发者ID:crapo,项目名称:sadlos2,代码行数:48,代码来源:GreaterThan.java


注:本文中的com.hp.hpl.jena.reasoner.rulesys.BuiltinException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。