Examples of Functor


Examples of com.codereligion.hammock.Functor

    @Override
    public void parse(Element element, Function<TypeElement, Type> storage) {
        final TypeElement typeElement = (TypeElement) element.getEnclosingElement();
        final ExecutableElement method = (ExecutableElement) element;
        final Functor annotation = method.getAnnotation(Functor.class);

        final String defaultName = method.getSimpleName().toString();
        final ClosureName delegate = new ClosureName(defaultName);
        final ClosureName name = new ClosureName(annotation.name().isEmpty() ? defaultName : annotation.name());

        final List<? extends VariableElement> parameters = method.getParameters();
        final boolean isStatic = method.getModifiers().contains(Modifier.STATIC);

        final Argument input;

        if (isStatic) {
            input = findInput(parameters);
        } else {
            input = new Argument(box(typeElement.asType()), "input");
        }

        final ClosureBuilder builder;

        TypeMirror returnType = method.getReturnType();
       
        if (returnType.getKind() == TypeKind.BOOLEAN) {
            builder = new ClosureBuilder(input, delegate);
        } else {
            builder = new ClosureBuilder(input, delegate, new Name(box(returnType).toString()));
        }

        builder.withName(name);
        builder.withStatic(isStatic);
        builder.withGraceful(annotation.graceful());
        builder.withNullTo(annotation.nullTo());

        if (isStatic) {
            builder.withDelegate(typeElement.getSimpleName().toString());
           
            for (VariableElement parameter : parameters) {
View Full Code Here

Examples of com.hp.hpl.jena.reasoner.rulesys.Functor

        ok =  predicate.isVariable() || pattern.predicate.isVariable() || predicate.equals(pattern.predicate);
        if (!ok) return false;
        if (object.isVariable() || pattern.object.isVariable()) return true;
        // Left with checking compatibility of ground literals
        if (Functor.isFunctor(object) && Functor.isFunctor(pattern.object)) {
            Functor functor = (Functor)object.getLiteralValue();
            Functor pFunctor = (Functor)pattern.object.getLiteralValue();
            return (functor.getName().equals(pFunctor.getName())
                            && functor.getArgs().length == pFunctor.getArgs().length);
        } else {
            return object.sameValueAs(pattern.object);
        }
    }
View Full Code Here

Examples of com.hp.hpl.jena.reasoner.rulesys.Functor

    public boolean variantOf(TriplePattern pattern) {
        Map<Node, Node> vmap = CollectionFactory.createHashedMap();
        if ( ! variantOf(subject, pattern.subject, vmap) ) return false;
        if ( ! variantOf(predicate, pattern.predicate, vmap) ) return false;
        if (Functor.isFunctor(object) && Functor.isFunctor(pattern.object)) {
            Functor functor = (Functor)object.getLiteralValue();
            Functor pFunctor = (Functor)pattern.object.getLiteralValue();
            if ( ! functor.getName().equals(pFunctor.getName()) ) return false;
            Node[] args = functor.getArgs();
            Node[] pargs = pFunctor.getArgs();
            if ( args.length != pargs.length ) return false;
            for (int i = 0; i < args.length; i++) {
                if ( ! variantOf(args[i], pargs[i], vmap) ) return false;
            }
            return true;
View Full Code Here

Examples of com.hp.hpl.jena.reasoner.rulesys.Functor

     * Side effects the variable bindings.
     */
    public boolean functorMatch(Triple t, LPInterpreter interpreter) {
        Node o = t.getObject();
        if (!Functor.isFunctor(o)) return false;
        Functor f = (Functor)o.getLiteralValue();
        if ( ! f.getName().equals(objectFunctor.getName())) return false;
        if ( f.getArgLength() != objectFunctor.getArgLength()) return false;
        Node[] fargs = f.getArgs();
        Node[] oFargs = objectFunctor.getArgs();
        for (int i = 0; i < fargs.length; i++) {
            if (!interpreter.unify(oFargs[i], fargs[i])) return false;
        }
        return true;
View Full Code Here

Examples of com.hp.hpl.jena.reasoner.rulesys.Functor

        if (node instanceof Node_RuleVariable) {
            return environment[((Node_RuleVariable)node).getIndex()];
        } else if (node instanceof Node_ANY) {
            return null;
        } else if (Functor.isFunctor(node)) {
            Functor functor = (Functor)node.getLiteralValue();
            if (functor.isGround()) return node;
            Node[] args = functor.getArgs();
            List<Node> boundargs = new ArrayList<Node>(args.length);
            for (int i = 0; i < args.length; i++) {
                Node binding = getBinding(args[i]);
                if (binding == null) {
                    // Not sufficent bound to instantiate functor yet
                    return null;
                }
                boundargs.add(binding);
            }
            Functor newf = new Functor(functor.getName(), boundargs);
            return Functor.makeFunctorNode( newf );
        } else {
            return node;
        }
    }
View Full Code Here

Examples of com.hp.hpl.jena.reasoner.rulesys.Functor

                            engine.deleteTriple(t, true);
                        }
                    }
              // }
            } else if (hClause instanceof Functor && isAdd) {
                Functor f = (Functor)hClause;
                Builtin imp = f.getImplementor();
                if (imp != null) {
                    imp.headAction(f.getBoundArgs(env), f.getArgLength(), context);
                } else {
                    throw new ReasonerException("Invoking undefined Functor " + f.getName() +" in " + rule.toShortString());
                }
            } else if (hClause instanceof Rule) {
                Rule r = (Rule)hClause;
                if (r.isBackward()) {
                    if (isAdd) {
View Full Code Here

Examples of com.hp.hpl.jena.reasoner.rulesys.Functor

        }
   
    @Test public void testIsFunctor()
        {
        Operation r = h.operationNamed( "isFunctor" );
        Functor f = new Functor( "f", new ArrayList<Node>() );
        Node functorNode = Node.createUncachedLiteral( f, "", FunctorDatatype.theFunctorDatatype );
        assertEquals( NODE_FALSE, r.evalValuenodeArray( "17" ) ) );
        assertEquals( NODE_FALSE, r.evalValuenodeArray( "spoo" ) ) );
        assertEquals( NODE_FALSE, r.evalValuenodeArray( "_blank" ) ) );
        assertEquals( NODE_TRUE, r.evalValuenew Node[] { functorNode } ) );
View Full Code Here

Examples of com.hp.hpl.jena.reasoner.rulesys.Functor

        }
   
    @Test public void testNotFunctor()
        {
        Operation r = h.operationNamed( "notFunctor" );
        Functor f = new Functor( "f", new ArrayList<Node>() );
        Node functorNode = Node.createUncachedLiteral( f, "", FunctorDatatype.theFunctorDatatype );
        assertEquals( NODE_TRUE, r.evalValuenodeArray( "17" ) ) );
        assertEquals( NODE_TRUE, r.evalValuenodeArray( "spoo" ) ) );
        assertEquals( NODE_TRUE, r.evalValuenodeArray( "_blank" ) ) );
        assertEquals( NODE_FALSE, r.evalValuenew Node[] { functorNode } ) );
View Full Code Here

Examples of com.hp.hpl.jena.reasoner.rulesys.Functor

          Item o = AbsRule.toItem( tp.getObject() );
          terms.add( Term.create( s, p, o ) );
          }
        else if (c instanceof Functor)
          {
          Functor f = (Functor) c;
          if (f.getName().equals( "hide" ))
              backwards.add( new AbsRule( AbsRule.asCondition( f ) ) );
          else
              expressions.add( AbsRule.asCondition( f ) );
          }
        else if (c instanceof com.hp.hpl.jena.reasoner.rulesys.Rule)
View Full Code Here

Examples of com.hp.hpl.jena.reasoner.rulesys.Functor

        assertEquals( node( "x" ), bindings[1] );
        }

    private Node makeFunctor( String f, Node... args )
        {
        Functor func = new Functor( f, Arrays.asList( args ) );
        return Node.createUncachedLiteral( func, "", FunctorDatatype.theFunctorDatatype );
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.