001: /******************************************************************
002: * File: NoValue.java
003: * Created by: Dave Reynolds
004: * Created on: 13-Apr-03
005: *
006: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: NoValue.java,v 1.13 2008/01/02 12:06:20 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.builtins;
010:
011: import com.hp.hpl.jena.reasoner.rulesys.*;
012: import com.hp.hpl.jena.graph.*;
013:
014: /**
015: * Can be used in two arg form (X, P) or three arg form (X, P, V).
016: * In three arg form it succeeds if the triple (X, P, V) is not
017: * currently present, in two arg form it succeeds if there is not value
018: * for (X, P, *).
019: *
020: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
021: * @version $Revision: 1.13 $ on $Date: 2008/01/02 12:06:20 $
022: */
023: public class NoValue extends BaseBuiltin {
024:
025: /**
026: * Return a name for this builtin, normally this will be the name of the
027: * functor that will be used to invoke it.
028: */
029: public String getName() {
030: return "noValue";
031: }
032:
033: /**
034: * This method is invoked when the builtin is called in a rule body.
035: * @param args the array of argument values for the builtin, this is an array
036: * of Nodes, some of which may be Node_RuleVariables.
037: * @param length the length of the argument list, may be less than the length of the args array
038: * for some rule engines
039: * @param context an execution context giving access to other relevant data
040: * @return return true if the buildin predicate is deemed to have succeeded in
041: * the current environment
042: */
043: public boolean bodyCall(Node[] args, int length, RuleContext context) {
044: if (length != 2 && length != 3) {
045: throw new BuiltinException(this , context, "builtin "
046: + getName() + " requires 2 or 3 arguments but saw "
047: + length);
048: }
049: Node obj = null;
050: if (length == 3) {
051: obj = getArg(2, args, context);
052: }
053: Node subj = getArg(0, args, context);
054: // Allow variables in subject position to correspond to wild cards
055: if (subj.isVariable()) {
056: subj = null;
057: }
058: Node pred = getArg(1, args, context);
059: if (pred.isVariable()) {
060: pred = null;
061: }
062: return !context.contains(subj, pred, obj);
063: }
064:
065: /**
066: * Flag as non-monotonic so the guard clause will get rerun after deferal
067: * as part of a non-trivial conflict set.
068: */
069: public boolean isMonotonic() {
070: return false;
071: }
072:
073: }
074:
075: /*
076: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
077: All rights reserved.
078:
079: Redistribution and use in source and binary forms, with or without
080: modification, are permitted provided that the following conditions
081: are met:
082:
083: 1. Redistributions of source code must retain the above copyright
084: notice, this list of conditions and the following disclaimer.
085:
086: 2. Redistributions in binary form must reproduce the above copyright
087: notice, this list of conditions and the following disclaimer in the
088: documentation and/or other materials provided with the distribution.
089:
090: 3. The name of the author may not be used to endorse or promote products
091: derived from this software without specific prior written permission.
092:
093: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
094: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
095: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
096: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
097: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
098: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
099: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
100: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
101: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
102: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103: */
|