Package org.openrdf.model.impl

Examples of org.openrdf.model.impl.LinkedHashModel


        return System.nanoTime() - time;
    }

    private static long benchmarkJsonLdJavaSesame(File path) throws SAXException, ParseException {
        System.out.println("JsonLd-Java-Sesame benchmark");
        AbstractModel model = new LinkedHashModel();

        List<File> files = listFiles(path);
        long time = System.nanoTime();
        for (File file : files) {
            try {
                InputStream inputStream = new FileInputStream(file);
                String baseURI = "http://example.org/baseuri/";
                org.openrdf.model.Model statements = Rio.parse(inputStream, baseURI, RDFFormat.JSONLD);
                model.addAll(statements);
            } catch (Exception e) {
                System.out.println("Skipped " + file.getAbsolutePath() + " due to " + e.getMessage());
            }
        }
        System.out.println("Model size = " + model.size());
        return System.nanoTime() - time;
    }
View Full Code Here


        result = result.substring(0, result.lastIndexOf('.')) + "-out." + ext;
        return result;
    }

    public Model createModelFromFile(String filename, String baseUri) throws IOException {
        Model model = new LinkedHashModel();
        if (filename != null) {
            try {
                RDFParser parser = Rio.createParser(SesameTestHelper.detectFileFormat(filename));
                parser.setRDFHandler(new ContextStatementCollector(model, ValueFactoryImpl.getInstance()));

                ParserConfig config = parser.getParserConfig();
                config.set(BasicParserSettings.PRESERVE_BNODE_IDS, true);
                config.addNonFatalError(BasicParserSettings.VERIFY_DATATYPE_VALUES);
                config.addNonFatalError(BasicParserSettings.VERIFY_LANGUAGE_TAGS);
                // Attempt to normalize known datatypes, including XML Schema
                config.set(BasicParserSettings.NORMALIZE_DATATYPE_VALUES, true);
                // Try not to fail when normalization fails
                config.addNonFatalError(BasicParserSettings.NORMALIZE_DATATYPE_VALUES);

                ParseErrorCollector errors = new ParseErrorCollector();
                parser.setParseErrorListener(errors);

                parser.parse(openStreamForResource(filename), baseUri);

                for(String nextFatalError : errors.getFatalErrors()) {
                    System.err.println("Fatal parse error was ignored : " + filename + " : "+ nextFatalError);
                }
                for(String nextError : errors.getErrors()) {
                    System.err.println("Parse error was ignored : " + filename + " : "+ nextError);
                }
                for(String nextWarning : errors.getWarnings()) {
                    System.err.println("Parse warning was ignored : " + filename + " : "+ nextWarning);
                }
            } catch (OpenRDFException e) {
                System.err.println("Fatal parse error caused failure : " + filename + " : "+ e.getMessage());
                //e.printStackTrace();
                // Avoid returning a partial model if there was a fatal error
                model = new LinkedHashModel();
            }
        }
        return model;
    }
View Full Code Here

        }
    }

    public String diff(Model model1, Model model2) {
        StringBuilder result = new StringBuilder();
        Model delta = new LinkedHashModel(model1);
        delta.removeAll(model2);
        String[] lines = new String[delta.size()];
        int i = 0;
        for (Statement s : delta) {
            lines[i++] = s.toString();
        }
        Arrays.sort(lines);
View Full Code Here

    @BeforeClass
    public void init() {
        rdfXmlParserTest = new RdfXmlParserTest();
        rdfXmlParserTest.init();
        model = new LinkedHashModel();
        streamProcessor = new StreamProcessor(RdfXmlParser.connect(SesameSink.connect(new StatementCollector(model))));
    }
View Full Code Here

        }
    };

    @BeforeClass
    public void init() throws SAXException {
        model = new LinkedHashModel();
       
        streamProcessor = new StreamProcessor(RdfaParser.connect(SesameSink.connect(new StatementCollector(model))));
        streamProcessor.setProperty(RdfaParser.ENABLE_VOCAB_EXPANSION, true);
    }
View Full Code Here

    @BeforeClass
    public void init() {
        nTriplesParserTest = new NTriplesParserTest();
        nTriplesParserTest.init();
        model = new LinkedHashModel();
        sp = new StreamProcessor(NTriplesParser.connect(SesameSink.connect(new StatementCollector(model))));
    }
View Full Code Here

        }
    };

    @BeforeClass
    public void init() throws SAXException, ClassNotFoundException {
        model = new LinkedHashModel();
    }
View Full Code Here

        // "{\"@id\":{\"@id\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/machine/DVC-1_8\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceElement\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceelement/DET-1_8\",\"http://igreen-projekt.de/ontologies/isoxml#deviceID\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"DVC-1\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceLocalizationLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"FF000000406564\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceProcessData\":[\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/13_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/6_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/14_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/11_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/8_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/4_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/5_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/10_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/2_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/21_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/15_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/16_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/19_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/17_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/3_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/12_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/7_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/18_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/9_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/22_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/20_8\"],\"http://igreen-projekt.de/ontologies/isoxml#deviceSerialNumber\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"12345\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceSoftwareVersion\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"01.009\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceStructureLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"31303030303030\"},\"http://igreen-projekt.de/ontologies/isoxml#workingSetMasterNAME\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"A000860020800001\"},\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":{\"@iri\":\"http://www.agroxml.de/rdfs#Machine\"},\"http://www.w3.org/2000/01/rdf-schema#label\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"Krone Device\"}}";
        final String inputstring = "{ \"@id\":\"http://nonexistent.com/abox#Document1823812\", \"@type\":\"http://nonexistent.com/tbox#Document\" }";
        final String expectedString = "(http://nonexistent.com/abox#Document1823812, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://nonexistent.com/tbox#Document) [null]";
        final Object input = JSONUtils.fromString(inputstring);

        final Graph graph = new LinkedHashModel();
        final ParseErrorCollector parseErrorListener = new ParseErrorCollector();
        final ParserConfig parserConfig = new ParserConfig();
        final SesameTripleCallback callback = new SesameTripleCallback(
                new StatementCollector(graph), ValueFactoryImpl.getInstance(), parserConfig,
                parseErrorListener);

        JsonLdProcessor.toRDF(input, callback);

        final Iterator<Statement> statements = graph.iterator();

        // contains only one statement (type)
        while (statements.hasNext()) {
            final Statement stmt = statements.next();
View Full Code Here

        final ParserConfig config = new ParserConfig();
        config.set(BasicParserSettings.FAIL_ON_UNKNOWN_DATATYPES, true);
        config.set(BasicParserSettings.FAIL_ON_UNKNOWN_LANGUAGES, true);
        rdfParser.setParserConfig(config);
        rdfParser.setValueFactory(vf);
        final Model model = new LinkedHashModel();
        rdfParser.setRDFHandler(new StatementCollector(model));

        rdfParser.parse(in, "foo:bar");

        assertEquals("Unexpected number of statements", 6, model.size());
        final Model bnodeModel = model.filter(null, uri1,
                vf.createLiteral(plainLit.getLabel(), XMLSchema.STRING));
        assertEquals("Blank node was not round-tripped", 1, bnodeModel.size());
        assertTrue("Blank node was not round-tripped as a blank node", bnodeModel.subjects()
                .iterator().next() instanceof BNode);
        if (rdfParser.getRDFFormat().supportsContexts()) {
            assertTrue(model.contains(st2));
        } else {
            assertTrue(model.contains(vf.createStatement(uri1, uri2, langLit)));
        }
        assertTrue(model.contains(st3));
        assertTrue(
                "missing statement with literal ending on newline",
                model.contains(vf.createStatement(uri1, uri2,
                        vf.createLiteral(litWithNewline.getLabel(), XMLSchema.STRING))));
        assertTrue(
                "missing statement with single quotes",
                model.contains(vf.createStatement(uri1, uri2,
                        vf.createLiteral(litWithSingleQuotes.getLabel(), XMLSchema.STRING))));
        assertTrue(
                "missing statement with single quotes",
                model.contains(vf.createStatement(uri1, uri2,
                        vf.createLiteral(litWithDoubleQuotes.getLabel(), XMLSchema.STRING))));
    }
View Full Code Here

    private ParserConfig parserConfig;

    private final ParseErrorListener parseErrorListener;

    public SesameTripleCallback() {
        this(new StatementCollector(new LinkedHashModel()));
    }
View Full Code Here

TOP

Related Classes of org.openrdf.model.impl.LinkedHashModel

Copyright © 2018 www.massapicom. 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.