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


Java SelectorFunction类代码示例

本文整理汇总了Java中org.apache.marmotta.ldpath.api.functions.SelectorFunction的典型用法代码示例。如果您正苦于以下问题:Java SelectorFunction类的具体用法?Java SelectorFunction怎么用?Java SelectorFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SelectorFunction类属于org.apache.marmotta.ldpath.api.functions包,在下文中一共展示了SelectorFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: programQuery

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
/**
 * Evaluate a path program passed as argument starting from the given context node and return a mapping for
 * each field in the program to the selected values.
 *
 * @param context
 * @param program
 * @return
 * @throws LDPathParseException
 */
public Map<String,Collection<?>> programQuery(Node context, Reader program) throws LDPathParseException {
    LdPathParser<Node> parser = new LdPathParser<Node>(backend,config,program);
    for(SelectorFunction<Node> function : functions) {
        parser.registerFunction(function);
    }
    for(String typeUri : transformers.keySet()) {
        parser.registerTransformer(typeUri, transformers.get(typeUri));
    }

    try {
        Program<Node> p = parser.parseProgram();

        Map<String,Collection<?>> result = new HashMap<String, Collection<?>>();

        for(FieldMapping<?,Node> mapping : p.getFields()) {
            result.put(mapping.getFieldName(),mapping.getValues(backend,context));
        }

        return result;

    } catch (ParseException e) {
        throw new LDPathParseException("error while parsing path expression",e);
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:34,代码来源:LDPath.java

示例2: parseProgram

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
/**
 * Parse a program passed as argument and return it for further use.
 *
 * @param program a reader containing the program in LDPath syntax
 * @return the parsed program
 * @throws LDPathParseException
 */
public Program<Node> parseProgram(Reader program) throws LDPathParseException {
    LdPathParser<Node> parser = new LdPathParser<Node>(backend,config,program);
    for(SelectorFunction<Node> function : functions) {
        parser.registerFunction(function);
    }
    for(String typeUri : transformers.keySet()) {
        parser.registerTransformer(typeUri, transformers.get(typeUri));
    }

    try {
        return parser.parseProgram();
    } catch (ParseException e) {
        throw new LDPathParseException("error while parsing path program",e);
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:23,代码来源:LDPath.java

示例3: registerFunction

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
/**
 * Register an LDPath function in this LDPath service. Can be used by other modules to plug in their own LDPath
 * functions as needed.
 *
 * @param function
 */
@Override
public void registerFunction(SelectorFunction<Value> function) {
    if (function instanceof AutoRegisteredLDPathFunction) {
        config.addFunction(((AutoRegisteredLDPathFunction) function).getLocalName(), function);
    } else {
        try {
            RepositoryConnection conn = sesameService.getConnection();
            try {
                conn.begin();
                SesameConnectionBackend backend = SesameConnectionBackend.withConnection(conn);
                config.addFunction(Constants.NS_LMF_FUNCS + function.getPathExpression(backend), function);
            } finally {
                conn.commit();
                conn.close();
            }
        } catch (RepositoryException e) {
            log.warn("Could not add function:" + function.getSignature(), e);
        }
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:27,代码来源:LDPathServiceImpl.java

示例4: scanForEvaluators

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
private void scanForEvaluators(Reflections annotatedClasses) {
    Set<Class<?>> defaultEvaluatorAnnotations = annotatedClasses.getTypesAnnotatedWith(Evaluator.class, true);

    Map<Class<? extends TestFunction>, Class<QueryEvaluator>> testFunctionEvaluators = new HashMap<>();
    Map<Class<? extends NodeSelector>, Class<QueryEvaluator>> defaultEvaluators = new HashMap<>();
    Map<Class<? extends NodeTest>, Class<TestEvaluator>> testEvaluators = new HashMap<>();
    Map<Class<? extends SelectorFunction>, Class<QueryEvaluator>> functionEvaluators = new HashMap<>();

    for (Class clazz : defaultEvaluatorAnnotations) {
        Evaluator evaluator = (Evaluator) clazz.getAnnotation(Evaluator.class);

        Class[] functionClasses = evaluator.value();

        for(Class functionClass : functionClasses) {
            if (ClassUtils.isAssignable(functionClass, TestFunction.class)) {
                logger.debug("Found evaluator {} for TestFunction {}", clazz.getCanonicalName(), functionClass.getCanonicalName());
                testFunctionEvaluators.put((Class<? extends TestFunction>) functionClass, clazz);
            } else if (ClassUtils.isAssignable(functionClass, NodeTest.class)) {
                logger.debug("Found evaluator {} for NodeTest {}", clazz.getCanonicalName(), functionClass.getCanonicalName());
                testEvaluators.put((Class<? extends NodeTest>) functionClass, clazz);
            } else if (ClassUtils.isAssignable(functionClass, SelectorFunction.class)) {
                logger.debug("Found evaluator {} for NodeFunction {}", clazz.getCanonicalName(), functionClass.getCanonicalName());
                functionEvaluators.put((Class<? extends SelectorFunction>) functionClass, clazz);
            } else {
                logger.debug("Found evaluator {} for NodeSelector {}", clazz.getCanonicalName(), functionClass.getCanonicalName());
                defaultEvaluators.put((Class<? extends NodeSelector>) functionClass, clazz);
            }
        }
    }

    evaluatorConfiguration.setDefaultEvaluators(defaultEvaluators);
    evaluatorConfiguration.setTestEvaluators(testEvaluators);
    evaluatorConfiguration.setTestFunctionEvaluators(testFunctionEvaluators);
    evaluatorConfiguration.setFunctionEvaluators(functionEvaluators);
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:36,代码来源:Anno4j.java

示例5: addDefaultFunctions

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
private void addDefaultFunctions() {
    Iterator<SelectorFunction> functions = functionLoader.iterator();
    while (functions.hasNext()) {
        try {
            SelectorFunction<Node> f = functions.next();
            log.info("registering LDPath function: {}", f.getSignature());
            addFunction(f);
        } catch (ServiceConfigurationError e) {
            log.warn("Unable to load function because of an "
                    + e.getClass().getSimpleName(), e);
        }
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:14,代码来源:DefaultConfiguration.java

示例6: listFunctions

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
/**
 * Return a list of all LDPath functions that have been registered in the LDPath installation.
 *
 * @HTTP 200 in case the functions exist; will return the function descriptions
 * @HTTP 500 in case there was an error accessing the triple store
 *
 * @return a list of JSON maps with the fields "name", "signature" and "description"
 */
@GET
@Path("/functions")
@Produces("application/json")
public Response listFunctions() {
    List<Map<String,String>> results = new ArrayList<Map<String, String>>();

    try {
        RepositoryConnection con = sesameService.getConnection();
        try {
            con.begin();
            SesameConnectionBackend backend = SesameConnectionBackend.withConnection(con);
            for(SelectorFunction<Value> function : ldPathService.getFunctions()) {
                Map<String,String> fmap = new HashMap<String, String>();
                fmap.put("name", function.getPathExpression(backend));
                fmap.put("signature",function.getSignature());
                fmap.put("description",function.getDescription());
                results.add(fmap);
            }
        } finally {
            con.commit();
            con.close();
        }
    } catch (RepositoryException e) {
        return Response.serverError().entity(e).build();
    }
    Collections.sort(results, new Comparator<Map<String, String>>() {
        @Override
        public int compare(Map<String, String> o1, Map<String, String> o2) {
            return Collator.getInstance().compare(o1.get("name"),o2.get("name"));
        }
    });

    return Response.ok().entity(results).build();
}
 
开发者ID:apache,项目名称:marmotta,代码行数:43,代码来源:LDPathWebService.java

示例7: getFunction

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
/**
 * Return a description of the function whose name is passed as path argument.
 *
 * @HTTP 200 in case the function exists; will return the function description
 * @HTTP 404 in case the function does not exist
 * @HTTP 500 in case there was an error accessing the triple store
 *
 * @return a JSON map with the fields "name", "signature" and "description"
 */
@GET
@Path("/functions/{name}")
@Produces("application/json")
public Response getFunction(@PathParam("name") String name) {
    try {
        RepositoryConnection con = sesameService.getConnection();
        try {
            con.begin();
            SesameConnectionBackend backend = SesameConnectionBackend.withConnection(con);

            for (SelectorFunction<Value> function : ldPathService.getFunctions()) {
                final String fName = function.getPathExpression(backend);
                if (name.equals(fName)) {
                    Map<String, String> fmap = new HashMap<String, String>();
                    fmap.put("name", fName);
                    fmap.put("signature", function.getSignature());
                    fmap.put("description", function.getDescription());
                    return Response.ok(fmap).build();
                }
            }
            return Response.status(Status.NOT_FOUND).entity("LDPath function with name " + name + " does not exist").build();
        } finally {
            con.commit();
            con.close();
        }
    } catch (RepositoryException e) {
        return Response.serverError().entity(e).build();
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:39,代码来源:LDPathWebService.java

示例8: getFunctions

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
/**
 * List all selector functions that are currently registered with LDPath.
 *
 * @return
 */
@Override
public Set<SelectorFunction<Value>> getFunctions() {
    Set<SelectorFunction<Value>> result = new HashSet<SelectorFunction<Value>>();
    result.addAll(config.getFunctions().values());

    return result;
}
 
开发者ID:apache,项目名称:marmotta,代码行数:13,代码来源:LDPathServiceImpl.java

示例9: evaluate

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
/**
 * Function to transform LDPath to SPARQL. Recursively splits the LDPath expression into the
 * separate parts and evaluate them. More specifically it creates the SPARQL query portions
 * for each considered part, using the Jena ARQ query engine
 *
 * @param nodeSelector The current NodeSelector of the LDPath
 * @param elementGroup ElementGroup containing the actual query parts
 * @param variable     The latest created variable
 * @return the latest referenced variable
 * @see <a href="https://jena.apache.org/documentation/query/">https://jena.apache.org/documentation/query/</a>
 */
public static Var evaluate(NodeSelector nodeSelector, ElementGroup elementGroup, Var variable, LDPathEvaluatorConfiguration evaluatorConfiguration) {

    Map<Class<? extends NodeSelector>, Class<QueryEvaluator>> defaultEvaluators = evaluatorConfiguration.getDefaultEvaluators();
    Map<Class<? extends TestFunction>, Class<QueryEvaluator>> testFunctionEvaluators = evaluatorConfiguration.getTestFunctionEvaluators();
    Map<Class<? extends NodeTest>, Class<TestEvaluator>> testEvaluators = evaluatorConfiguration.getTestEvaluators();
    Map<Class<? extends SelectorFunction>, Class<QueryEvaluator>> functionEvaluators = evaluatorConfiguration.getFunctionEvaluators();

    try {
        if (defaultEvaluators.containsKey(nodeSelector.getClass())) {
            return defaultEvaluators.get(nodeSelector.getClass()).newInstance().evaluate(nodeSelector, elementGroup, variable, evaluatorConfiguration);
        } else if (nodeSelector instanceof TestingSelector) {
            TestingSelector testingSelector = (TestingSelector) nodeSelector;

            if (testingSelector.getTest() instanceof FunctionTest) {
                FunctionTest functionTest = (FunctionTest) testingSelector.getTest();

                if (testFunctionEvaluators.containsKey(functionTest.getTest().getClass())) {
                    return testFunctionEvaluators.get(functionTest.getTest().getClass()).newInstance().evaluate(nodeSelector, elementGroup, variable, evaluatorConfiguration);
                } else {
                    throw new IllegalStateException("No FunctionTest evaluator for " + functionTest.getClass().getCanonicalName());
                }
            } else {
                NodeTest nodeTest = testingSelector.getTest();

                if (testEvaluators.containsKey(nodeTest.getClass())) {
                    return testEvaluators.get(nodeTest.getClass()).newInstance().evaluate(nodeSelector, elementGroup, variable, evaluatorConfiguration);
                } else {
                    throw new IllegalStateException("No NodeTest evaluator for " + nodeTest.getClass().getCanonicalName());
                }
            }
        } else if (nodeSelector instanceof FunctionSelector) {
            FunctionSelector functionSelector = (FunctionSelector) nodeSelector;

            if (functionEvaluators.containsKey(functionSelector.getFunction().getClass())) {
                return functionEvaluators.get(functionSelector.getFunction().getClass()).newInstance().evaluate(nodeSelector, elementGroup, variable, evaluatorConfiguration);
            } else {
                throw new IllegalStateException("No Function evaluator found for " + functionSelector.getClass().getCanonicalName());
            }
        } else {
            throw new IllegalStateException(nodeSelector.getClass() + " is not supported.");
        }
    } catch (Exception e) {
        logger.error("{}", e);
        throw new IllegalStateException("Could not instantiate evaluator for " + nodeSelector.getClass());
    }
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:58,代码来源:LDPathEvaluator.java

示例10: getFunctionEvaluators

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
public Map<Class<? extends SelectorFunction>, Class<QueryEvaluator>> getFunctionEvaluators() {
    return functionEvaluators;
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:4,代码来源:LDPathEvaluatorConfiguration.java

示例11: setFunctionEvaluators

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
public void setFunctionEvaluators(Map<Class<? extends SelectorFunction>, Class<QueryEvaluator>> functionEvaluators) {
    this.functionEvaluators = functionEvaluators;
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:4,代码来源:LDPathEvaluatorConfiguration.java

示例12: Configuration

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
public Configuration() {
    namespaces   = new HashMap<String,String>();
    transformers = new HashMap<String, NodeTransformer<?, Node>>();
    functions    = new HashMap<String, SelectorFunction<Node>>();
    testFunctions = new HashMap<String, TestFunction<Node>>();
}
 
开发者ID:apache,项目名称:marmotta,代码行数:7,代码来源:Configuration.java

示例13: addFunction

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
private void addFunction(SelectorFunction<Node> function) {
    addFunction(Constants.NS_LMF_FUNCS + function.getPathExpression(null), function);
}
 
开发者ID:apache,项目名称:marmotta,代码行数:4,代码来源:DefaultConfiguration.java

示例14: pathQuery

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
/**
 * Execute a single path query starting from the given context node and return a collection of nodes resulting
 * from the selection. Default namespaces (rdf, rdfs, skos, dc, foaf) are added automatically, further namespaces
 * need to be passed as arguments.
 * <p/>
 * Paths need to conform to the RdfPath Selector syntax described at
 * <a href="http://code.google.com/p/kiwi/wiki/RdfPathLanguage#Path_Selectors">the wiki</a>.
 * For example, the following selection would select the names of all friends:
 * <p/>
 * <code>
 * foaf:knows / foaf:name
 * </code>
 * <p/>
 * Note that since this method returns a collection of nodes, no transformations can be used.
 *
 * @param context the context node where to start the path query
 * @param path  the LDPath path specification
 * @param namespaces an optional map mapping namespace prefixes to URIs (used for lookups of prefixes used in the path);
 *                   can be null
 * @return a collection of nodes
 * @throws LDPathParseException when the path passed as argument is not valid
 */
public Collection<Node> pathQuery(Node context, String path, Map<String, String> namespaces) throws LDPathParseException {
    LdPathParser<Node> parser = new LdPathParser<Node>(backend,config,new StringReader(path));
    for(SelectorFunction<Node> function : functions) {
        parser.registerFunction(function);
    }
    for(String typeUri : transformers.keySet()) {
        parser.registerTransformer(typeUri,transformers.get(typeUri));
    }

    try {
        NodeSelector<Node> selector = parser.parseSelector(namespaces);

        return selector.select(backend,context,null,null);

    } catch (ParseException e) {
        throw new LDPathParseException("error while parsing path expression",e);
    }

}
 
开发者ID:apache,项目名称:marmotta,代码行数:42,代码来源:LDPath.java

示例15: pathTransform

import org.apache.marmotta.ldpath.api.functions.SelectorFunction; //导入依赖的package包/类
/**
 * Execute a single path query starting from the given context node and return a collection of nodes resulting
 * from the selection. Default namespaces (rdf, rdfs, skos, dc, foaf) are added automatically, further namespaces
 * need to be passed as arguments.
 * <p/>
 * Paths need to conform to the RdfPath Selector syntax described at
 * <a href="http://code.google.com/p/kiwi/wiki/RdfPathLanguage#Path_Selectors">the wiki</a>.
 * For example, the following selection would select the names of all friends:
 * <p/>
 * <code>
 * foaf:knows / foaf:name
 * </code>
 * <p/>
 * Note that since this method returns a collection of nodes, no transformations can be used.
 *
 * @param context the context node where to start the path query
 * @param path  the LDPath path specification
 * @param namespaces an optional map mapping namespace prefixes to URIs (used for lookups of prefixes used in the path);
 *                   can be null
 * @return a collection of nodes
 * @throws LDPathParseException when the path passed as argument is not valid
 */
public <T> Collection<T> pathTransform(Node context, String path, Map<String, String> namespaces) throws LDPathParseException {
    LdPathParser<Node> parser = new LdPathParser<Node>(backend,config,new StringReader(path));
    for(SelectorFunction<Node> function : functions) {
        parser.registerFunction(function);
    }
    for(String typeUri : transformers.keySet()) {
        parser.registerTransformer(typeUri,transformers.get(typeUri));
    }

    try {
        FieldMapping<T,Node> mapping = parser.parseRule(namespaces);

        return mapping.getValues(backend, context);

    } catch (ParseException e) {
        throw new LDPathParseException("error while parsing path expression",e);
    }

}
 
开发者ID:apache,项目名称:marmotta,代码行数:42,代码来源:LDPath.java


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