本文整理汇总了Java中org.apache.marmotta.ldpath.model.fields.FieldMapping.getValues方法的典型用法代码示例。如果您正苦于以下问题:Java FieldMapping.getValues方法的具体用法?Java FieldMapping.getValues怎么用?Java FieldMapping.getValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.marmotta.ldpath.model.fields.FieldMapping
的用法示例。
在下文中一共展示了FieldMapping.getValues方法的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"));
}
示例2: 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"));
}
示例3: 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));
}
示例4: 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"));
}
示例5: 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));
}
示例6: 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>"));
}
示例7: 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());
}
示例8: 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());
}
示例9: 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"));
}
示例10: 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);
}
示例11: testLatest
import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入方法依赖的package包/类
@Test
public void testLatest() throws ParseException {
final LdPathParser<Value> parser = createParserFromString("fn:latest(<" + 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(now, obj);
}
示例12: testJsonPathFunction
import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入方法依赖的package包/类
@Test
public void testJsonPathFunction() throws ParseException {
final URI ctx = repository.getValueFactory().createURI(NSS.get("ex") + "Quiz");
final LdPathParser<Value> parser = createParserFromString("fn:jsonpath(\"" + path + "\", <http://www.w3.org/2011/content#chars>) :: 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());
}
示例13: pathTransform
import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入方法依赖的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);
}
}
示例14: evaluateRule
import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入方法依赖的package包/类
protected Collection<Object> evaluateRule(final String ldPath, URI context) throws ParseException {
final LdPathParser<Value> parser = createParserFromString(ldPath);
final FieldMapping<Object, Value> rule = parser.parseRule(NSS);
final Collection<Object> values = rule.getValues(backend, context);
return values;
}
示例15: testMin
import org.apache.marmotta.ldpath.model.fields.FieldMapping; //导入方法依赖的package包/类
@Test
public void testMin() throws ParseException {
int iMin = Integer.MAX_VALUE;
long lMin = Long.MAX_VALUE;
float fMin = Float.MAX_VALUE;
double dMin = Double.MAX_VALUE;
for (int i = 0; i < iData.length; i++) {
iMin = Math.min(iMin, iData[i]);
lMin = Math.min(lMin, lData[i]);
fMin = Math.min(fMin, fData[i]);
dMin = Math.min(dMin, dData[i]);
}
final LdPathParser<Value> intParser = createParserFromString("fn:min(<" + iProp.stringValue() + ">) :: xsd:int");
final FieldMapping<Object, Value> intRule = intParser.parseRule(NSS);
final Collection<Object> intResult = intRule.getValues(backend, subject);
Assert.assertEquals("Integer", 1, intResult.size());
final Object intNext = intResult.iterator().next();
Assert.assertTrue("Integer (type)", intNext instanceof Integer);
Assert.assertEquals("Integer (result)", iMin, intNext);
final LdPathParser<Value> longParser = createParserFromString("fn:min(<" + lProp.stringValue() + ">) :: xsd:long");
final FieldMapping<Object, Value> longRule = longParser.parseRule(NSS);
final Collection<Object> longResult = longRule.getValues(backend, subject);
Assert.assertEquals("Long", 1, longResult.size());
final Object longNext = longResult.iterator().next();
Assert.assertTrue("Long (type)", longNext instanceof Long);
Assert.assertEquals("Long (result)", lMin, longNext);
final LdPathParser<Value> floatParser = createParserFromString("fn:min(<" + fProp.stringValue() + ">) :: xsd:float");
final FieldMapping<Object, Value> floatRule = floatParser.parseRule(NSS);
final Collection<Object> floatResult = floatRule.getValues(backend, subject);
Assert.assertEquals("Float", 1, floatResult.size());
final Object floatNext = floatResult.iterator().next();
Assert.assertTrue("Float (type)", floatNext instanceof Float);
Assert.assertEquals("Float (result)", fMin, floatNext);
final LdPathParser<Value> doubleParser = createParserFromString("fn:min(<" + dProp.stringValue() + ">) :: xsd:double");
final FieldMapping<Object, Value> doubleRule = doubleParser.parseRule(NSS);
final Collection<Object> doubleResult = doubleRule.getValues(backend, subject);
Assert.assertEquals("Double", 1, doubleResult.size());
final Object doubleNext = doubleResult.iterator().next();
Assert.assertTrue("Double (type)", doubleNext instanceof Double);
Assert.assertEquals("Double (result)", dMin, doubleNext);
}