use of org.apache.jena.rdf.model.Model in project jena by apache.
the class rdflangtest method oneManifestEarl.
static void oneManifestEarl(String testManifest) {
EarlReport report = new EarlReport(systemURI, name, version, homepage);
FactoryTestRiot.report = report;
TestSuite suite = FactoryTestRiot.make(testManifest, null, null);
SimpleTestRunner.runSilent(suite);
Model model = report.getModel();
model.setNsPrefix("rdft", VocabLangRDF.getURI());
model.setNsPrefix("turtletest", "http://www.w3.org/2013/TurtleTests/manifest.ttl#");
insertMetaOld(report);
RDFDataMgr.write(System.out, model, Lang.TURTLE);
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class TestGenericRuleReasonerConfig method testRuleLoadingWithOverridenBuiltins.
public void testRuleLoadingWithOverridenBuiltins() {
List<Node> savedNode = new ArrayList<>();
Builtin b = new BaseBuiltin() {
@Override
public String getName() {
return "groo";
}
@Override
public int getArgLength() {
return 1;
}
@Override
public void headAction(Node[] args, int length, RuleContext context) {
savedNode.add(getArg(0, args, context));
}
};
BuiltinRegistry r = new OverrideBuiltinRegistry(BuiltinRegistry.theRegistry);
r.register(b);
assertEquals(b, r.getImplementation("groo"));
List<Rule> rules = new ArrayList<>();
//
// note that the head action does not appear to fire unless we put a triple in the head as well.. is
// this expected?
//
rules.add(parseRule("[ (?instance rdf:type ?type) -> groo(?type) ]", r));
GenericRuleReasoner article = new GenericRuleReasoner(rules);
article.setMode(GenericRuleReasoner.FORWARD_RETE);
Model input = ModelFactory.createDefaultModel();
input.add(input.createResource(), RDF.type, input.createResource("http://example.com/Renegade"));
InfModel output = ModelFactory.createInfModel(article, input);
// not optional, inferences are not run if we don't trigger them
output.size();
assertEquals(1, savedNode.size());
assertEquals("http://example.com/Renegade", savedNode.get(0).getURI());
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class TestXMLFeatures method doBadPropTest.
void doBadPropTest(String lg) throws IOException {
Model m = createMemModel();
m.add(m.createResource(), m.createProperty("http://example/", "foo#"), "foo");
File file = File.createTempFile("rdf", ".xml");
// file.deleteOnExit();
FileOutputStream fwriter = new FileOutputStream(file);
try {
m.write(fwriter, lg);
fwriter.close();
fail("Writer did not detect bad property URI");
} catch (InvalidPropertyURIException je) {
// as required, so nowt to do.
}
file.delete();
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class XMLOutputTestBase method check.
protected void check(String filename, String encoding, String regexPresent, String regexAbsent, boolean errorExpected, Change code, String base) throws IOException {
blockLogger();
boolean errorsFound;
Model m = createMemModel();
try (InputStream in = new FileInputStream(filename)) {
m.read(in, base);
}
@SuppressWarnings("resource") Writer sw;
ByteArrayOutputStream bos = null;
if (encoding == null)
sw = new StringWriter();
else {
bos = new ByteArrayOutputStream();
sw = new OutputStreamWriter(bos, encoding);
}
Properties p = (Properties) System.getProperties().clone();
RDFWriter writer = m.getWriter(lang);
code.modify(m, writer);
writer.write(m, sw, base);
sw.close();
String contents;
if (encoding == null)
contents = sw.toString();
else {
contents = bos.toString(encoding);
}
try {
Model m2 = createMemModel();
m2.read(new StringReader(contents), base);
assertTrue("Data got changed.", m.isIsomorphicWith(m2));
if (regexPresent != null)
assertTrue("Should find /" + regexPresent + "/", Pattern.compile(regexPresent, Pattern.DOTALL).matcher(contents).find());
if (regexAbsent != null)
assertTrue("Should not find /" + regexAbsent + "/", !Pattern.compile(regexAbsent, Pattern.DOTALL).matcher(contents).find());
contents = null;
} finally {
errorsFound = unblockLogger();
System.setProperties(p);
if (contents != null) {
System.err.println("===================");
System.err.println("Offending content - " + toString());
System.err.println("===================");
System.err.println(contents);
System.err.println("===================");
}
}
assertEquals("Errors (not) detected.", errorExpected, errorsFound);
}
use of org.apache.jena.rdf.model.Model in project jena by apache.
the class sdbdump method execCmd.
@Override
protected void execCmd(List<String> args) {
// This is a streamable syntax.
String syntax = "N-QUADS";
if (contains(argDeclSyntax))
syntax = getArg(argDeclSyntax).getValue();
Lang lang = RDFLanguages.nameToLang(syntax);
try {
if (modGraph.getGraphName() == null) {
if (!RDFLanguages.isQuads(lang))
cmdError("Not a 'quads' language (try 'N-Quads' or 'TriG')", true);
Dataset dataset = getModStore().getDataset();
RDFDataMgr.write(System.out, dataset, lang);
} else {
Model model = modGraph.getModel(getStore());
RDFDataMgr.write(System.out, model, lang);
}
} catch (CmdException ex) {
throw ex;
} catch (Exception ex) {
System.err.println("Exception: " + ex + " :: " + ex.getMessage());
ex.printStackTrace(System.err);
}
}
Aggregations