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


Java FieldMapping类代码示例

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


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

示例1: testCssSelectFunction

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testCssSelectFunction() throws ParseException {

    final LdPathParser<Value> parser = createParserFromString("fn:css(\"p\", foo:html) :: xsd:string");
    final FieldMapping<Object, Value> rule = parser.parseRule(NSS);

    final Collection<Object> result = rule.getValues(backend, resource);
    assertEquals(3, result.size());

    for (Object object : result) {
        String s = object.toString();
        assertThat("String start", s, CoreMatchers.startsWith("<p"));
        assertThat("String end", s, CoreMatchers.endsWith("</p>"));
    }

    final LdPathParser<Value> parser2 = createParserFromString("fn:css(\"p#p2\", foo:html) :: xsd:string");
    final FieldMapping<Object, Value> rule2 = parser2.parseRule(NSS);

    final Collection<Object> result2 = rule2.getValues(backend, resource);
    assertEquals(1, result2.size());

    String txt = result2.iterator().next().toString();
    assertThat(txt, containsString("Most marmots are highly social and use loud whistles to communicate with one another"));

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

示例2: programQuery

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的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

示例3: testFirst

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testFirst() throws ParseException {
    final URI ctx1 = repository.getValueFactory().createURI("http://www.example.com/1");
    final URI ctx2 = repository.getValueFactory().createURI("http://www.example.com/2");

    LdPathParser<Value> parser = createParserFromString("fn:first(foo:not_valid, foo:title, foo:subtitle, foo:not_valid2) :: xsd:string; ");
    final FieldMapping<Object, Value> field = parser.parseRule(NSS);

    final Collection<Object> result = field.getValues(backend, ctx1);
    assertEquals(1, result.size());
    assertThat(result, CoreMatchers.hasItem("One"));

    final Collection<Object> result2 = field.getValues(backend, ctx2);
    assertEquals(1, result2.size());
    assertThat(result2, CoreMatchers.hasItem("Two"));
}
 
开发者ID:apache,项目名称:marmotta,代码行数:17,代码来源:FunctionsTest.java

示例4: testFirst2

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testFirst2() throws ParseException {
    final URI ctx1 = repository.getValueFactory().createURI("http://www.example.com/1");
    final URI ctx2 = repository.getValueFactory().createURI("http://www.example.com/2");

    LdPathParser<Value> parser = createParserFromString("fn:first(foo:i) :: xsd:int; ");
    final FieldMapping<Object, Value> field = parser.parseRule(NSS);

    final Collection<Object> result = field.getValues(backend, ctx1);
    assertEquals(3, result.size());
    assertThat(result, CoreMatchers.hasItem(1));

    final Collection<Object> result2 = field.getValues(backend, ctx2);
    assertEquals(1, result2.size());
    assertThat(result2, CoreMatchers.hasItem(99));
}
 
开发者ID:apache,项目名称:marmotta,代码行数:17,代码来源:FunctionsTest.java

示例5: testLast

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testLast() throws ParseException {
    final URI ctx1 = repository.getValueFactory().createURI("http://www.example.com/1");
    final URI ctx2 = repository.getValueFactory().createURI("http://www.example.com/2");

    LdPathParser<Value> parser = createParserFromString("fn:last(foo:not_valid, foo:title, foo:subtitle, foo:not_valid2) :: xsd:string; ");
    final FieldMapping<Object, Value> field = parser.parseRule(NSS);

    final Collection<Object> result = field.getValues(backend, ctx1);
    assertEquals(1, result.size());
    assertThat(result, CoreMatchers.hasItem("SubOne"));

    final Collection<Object> result2 = field.getValues(backend, ctx2);
    assertEquals(1, result2.size());
    assertThat(result2, hasItem("SubTwo"));
}
 
开发者ID:apache,项目名称:marmotta,代码行数:17,代码来源:FunctionsTest.java

示例6: testLast2

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testLast2() throws ParseException {
    final URI ctx1 = repository.getValueFactory().createURI("http://www.example.com/1");
    final URI ctx2 = repository.getValueFactory().createURI("http://www.example.com/2");

    LdPathParser<Value> parser = createParserFromString("fn:last(foo:i, ex:not_here) :: xsd:int; ");
    final FieldMapping<Object, Value> field = parser.parseRule(NSS);

    final Collection<Object> result = field.getValues(backend, ctx1);
    assertEquals(3, result.size());
    assertThat(result, CoreMatchers.<Object> hasItems(1, 2, 3));

    final Collection<Object> result2 = field.getValues(backend, ctx2);
    assertEquals(1, result2.size());
    assertThat(result2, hasItem(99));
}
 
开发者ID:apache,项目名称:marmotta,代码行数:17,代码来源:FunctionsTest.java

示例7: evaluateRule

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
protected ImmutableCollection<Object> evaluateRule(final String ldPath, IRI context)
    throws ParseException {
  final LdPathParser<Value> parser = createParserFromString(ldPath);
  final FieldMapping<Object, Value> rule = parser.parseRule(NAMESPACES);

  return ImmutableList.copyOf(rule.getValues(backend, context));
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:8,代码来源:AbstractFunctionTest.java

示例8: prepareQueryLDPathProgram

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
/**
 * 
 * @param ldpathProgram the LDPath program as string
 * @param selectedFields the selected fields of the query
 * @param backend the RDFBackend  (only needed for logging)
 * @param ldPath the {@link LDPath} used to parse the program.
 * @return the pre-processed and validated program
 * @throws LDPathParseException if the parsed LDPath program string is not
 * valid
 * @throws IllegalStateException if the fields selected by the LDPath
 * program conflict with the fields selected by the query.
 */
public static Program<Object> prepareQueryLDPathProgram(String ldpathProgram,
                                            Set<String> selectedFields,
                                            AbstractBackend backend,
                                            EntityhubLDPath ldPath) throws LDPathParseException {
    Program<Object> program = ldPath.parseProgram(getReader(ldpathProgram));
    
    //We need to do two things:
    // 1) ensure that no fields define by LDPath are also selected
    StringBuilder conflicting = null;
    // 2) add the field of the result score if not defined by LDPath
    String resultScoreProperty = RdfResourceEnum.resultScore.getUri();
    boolean foundRsultRankingField = false;
    for(FieldMapping<?,Object> ldPathField : program.getFields()){
        String field = ldPathField.getFieldName();
        if(!foundRsultRankingField && resultScoreProperty.equals(field)){
            foundRsultRankingField = true;
        }
        //remove from selected fields -> if we decide later that
        //this should not be an BAD_REQUEST
        if(selectedFields.remove(ldPathField.getFieldName())){
            if(conflicting == null){
                conflicting = new StringBuilder();
            }
            conflicting.append('\n').append("  > ")
            .append(ldPathField.getPathExpression(backend));
        }
    }
    if(conflicting != null){ //there are conflicts
        throw new IllegalStateException("Selected Fields conflict with Fields defined by" +
            "the LDPath program! Conflicts: "+conflicting.toString());
    }
    if(!foundRsultRankingField){ //if no mapping for the result score
        program.addMapping(RESULT_SCORE_MAPPING); //add the default mapping
    }
    return program;
}
 
开发者ID:teamdigitale,项目名称:ontonethub,代码行数:49,代码来源:LDPathHelper.java

示例9: testCleanHtmlFunction

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testCleanHtmlFunction() throws ParseException {

    final LdPathParser<Value> parser = createParserFromString("fn:cleanHtml(foo:html) :: xsd:string");
    final FieldMapping<Object, Value> rule = parser.parseRule(NSS);

    final Collection<Object> result = rule.getValues(backend, resource);
    assertEquals(1, result.size());
    final String txt = result.iterator().next().toString();

    assertThat("attribute: id", txt, not(containsString("id=\"")));
    assertThat("element: h1", txt, not(containsString("<h1>")));
    assertThat("element: div", txt, not(containsString("<div>")));
    assertThat("element: p", txt, containsString("<p>"));
}
 
开发者ID:apache,项目名称:marmotta,代码行数:16,代码来源:HtmlFunctionsTest.java

示例10: testXpathFunction

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testXpathFunction() throws ParseException {
    final URI ctx = repository.getValueFactory().createURI(NSS.get("ex") + "Quiz");

    final LdPathParser<Value> parser = createParserFromString("fn:xpath(\"/quiz/question[" +
            index +
            "]/answers/answer[@correct='true']/text()\", foo:xml) :: xsd:string");
    final FieldMapping<Object, Value> rule = parser.parseRule(NSS);
    final Collection<Object> values = rule.getValues(backend, ctx);

    Assert.assertEquals(1, values.size());
    Assert.assertEquals(answer, values.iterator().next());
}
 
开发者ID:apache,项目名称:marmotta,代码行数:14,代码来源:XPathFunctionTest.java

示例11: testRemoveTags

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testRemoveTags() throws ParseException {
    String result = "A quiz is a form of game or mind sport in which the players (as individuals or in teams) attempt to answer questions correctly.";

    final URI context = repository.getValueFactory().createURI(NSS.get("ex") + "Text");

    final LdPathParser<Value> parser = createParserFromString("fn:removeTags(foo:formatted) :: xsd:string");
    final FieldMapping<Object, Value> rule = parser.parseRule(NSS);
    final Collection<Object> values = rule.getValues(backend, context);

    Assert.assertEquals(1, values.size());
    Assert.assertEquals(result, values.iterator().next());
}
 
开发者ID:apache,项目名称:marmotta,代码行数:14,代码来源:RemoveXmlTagsFunctionTest.java

示例12: getField

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
public FieldMapping<?,Node> getField(String name) {
    for(FieldMapping<?,Node> m : fields) {
        if(name.equals(m.getFieldName())) {
            return m;
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:marmotta,代码行数:9,代码来源:Program.java

示例13: execute

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
/**
 * Executes this Program on the parsed {@link RDFBackend backend}. 
 * @param context The context of the execution
 * @return The result
 */
public Map<String,Collection<?>> execute(RDFBackend<Node> backend, Node context) {
    Map<String,Collection<?>> result = new HashMap<String, Collection<?>>();

    for(FieldMapping<?,Node> mapping : getFields()) {
        result.put(mapping.getFieldName(),mapping.getValues(backend,context));
    }
    return result;
}
 
开发者ID:apache,项目名称:marmotta,代码行数:14,代码来源:Program.java

示例14: testConcat

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testConcat() throws ParseException {

    LdPathParser<Value> parser = createParserFromString("fn:concat(foo:title, \" \", foo:subtitle) :: xsd:string; ");
    final URI context = repository.getValueFactory().createURI("http://www.example.com/1");

    final FieldMapping<Object, Value> field = parser.parseRule(NSS);
    final Collection<Object> result = field.getValues(backend, context);

    assertThat(result, CoreMatchers.hasItem("One SubOne"));
}
 
开发者ID:apache,项目名称:marmotta,代码行数:12,代码来源:FunctionsTest.java

示例15: testEarliest

import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入依赖的package包/类
@Test
public void testEarliest() throws ParseException {
    final LdPathParser<Value> parser = createParserFromString("fn:earliest(<" + prop.stringValue() + ">) :: xsd:dateTime");
    final FieldMapping<Object, Value> rule = parser.parseRule(NSS);
    final Collection<Object> result = rule.getValues(backend, uri);

    Assert.assertEquals(1, result.size());

    final Object obj = result.iterator().next();
    Assert.assertEquals(first, obj);
}
 
开发者ID:apache,项目名称:marmotta,代码行数:12,代码来源:DateFunctionsTest.java


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