Package org.apache.clerezza.rdf.core

Examples of org.apache.clerezza.rdf.core.Graph


    @Test
    public void testRdfXmlParser() {
        ParsingProvider provider = new JenaParserProvider();
        InputStream nTriplesIn = getClass().getResourceAsStream("test-04.nt");
        InputStream rdfIn = getClass().getResourceAsStream("test-04.rdf");
        Graph graphFromNTriples = parse(provider, nTriplesIn, "text/rdf+nt", null);
        Graph graphFromTurtle = parse(provider, rdfIn, "application/rdf+xml", null);
        Assert.assertEquals(graphFromNTriples, graphFromTurtle);
    }
View Full Code Here


    @Test
    public void testTurtleParserWithArgument() {
        ParsingProvider provider = new JenaParserProvider();
        InputStream nTriplesIn = getClass().getResourceAsStream("test-04.nt");
        InputStream turtleIn = getClass().getResourceAsStream("test-04.ttl");
        Graph graphFromNTriples = parse(provider, nTriplesIn, "text/rdf+nt", null);
        Graph graphFromTurtle = parse(provider, turtleIn, "text/turtle;charset=UTF-", null);
        Assert.assertEquals(graphFromNTriples, graphFromTurtle);
    }
View Full Code Here

  @Path("replace-subgraph")
  public void replaceSubGraph(@QueryParam("graph") UriRef graphUri,
      @FormParam("assert") String assertedString,
      @FormParam("revoke") String revokedString,
      @FormParam("format") @DefaultValue("text/turtle") String format) {
    final Graph assertedGraph;
    final Graph revokedGraph;
    try {
      assertedGraph = parser.parse(new ByteArrayInputStream(assertedString.getBytes("utf-8")),
          format);
      revokedGraph = parser.parse(new ByteArrayInputStream(assertedString.getBytes("utf-8")),
          format);
View Full Code Here

  // Thanks to Reto
  public static void main(String[] args) {
    InputStream in = Utils.getResourceAsStream("data/data.ttl");
    Parser parser = Parser.getInstance();
    Graph g = parser.parse(in, SupportedFormat.TURTLE);
    Serializer serializer = Serializer.getInstance();
    serializer.serialize(System.out, g, SupportedFormat.N_TRIPLE);
  }
View Full Code Here

     *
     * @return
     */
    public Set<ExecutionNode> getExecutionNodes() {
        if (_executionNodes == null) {
            Graph ep;
            try {
                ep = chain.getExecutionPlan();
            } catch (ChainException e) {
                ep = null;
            }
View Full Code Here

        Chain defaultChain = chainManager.getDefault();
        if(defaultChain == null){
            throw new IllegalStateException("Currently no enhancement chain is " +
                "active. Please configure a Chain or enable the default chain");
        }
        Graph ep;
        try {
            ep = defaultChain.getExecutionPlan();
        } catch (ChainException e) {
            throw new IllegalStateException("Unable to get Execution Plan for " +
                "default enhancement chain (name: '"+defaultChain.getName()+
View Full Code Here

    @Test
    public void testBackup() throws IOException {
        //Graph downloadedTestGraphX = null;
        //Graph downloadedTestGraphY = null;
        Graph downloadedBackupContentsGraph = null;

        byte[] download = backup.createBackup();
        ByteArrayInputStream bais = new ByteArrayInputStream(download);
        ZipInputStream compressedTcs = new ZipInputStream(bais);

        Map<String, TripleCollection> extractedTc = new HashMap<String, TripleCollection>();
        String folder = "";
        ZipEntry entry;
        while ((entry = compressedTcs.getNextEntry()) != null) {
            String entryName = entry.getName();
            if (entry.isDirectory()) {
                folder = entryName;
            } else {
                Assert.assertTrue(entryName.startsWith(folder+testGraphFileName)
                        || entryName.equals(backupContentFileName));
                ByteArrayOutputStream baos = new ByteArrayOutputStream(download.length);
                int count;
                byte buffer[] = new byte[2048];
                while ((count = compressedTcs.read(buffer, 0, 2048)) != -1) {
                    baos.write(buffer, 0, count);
                }
                ByteArrayInputStream serializedGraph = new ByteArrayInputStream(
                        baos.toByteArray());
                /*if (entryName.equals(folder+testGraphFileName + ".nt")) {
                    downloadedTestGraphX = parser.parse(serializedGraph,
                            SupportedFormat.N_TRIPLE, null);
                } else if (entryName.startsWith(folder+testGraphFileName)) {
                    downloadedTestGraphY = parser.parse(serializedGraph,
                            SupportedFormat.N_TRIPLE, null);
                }*/
                if (entryName.equals(backupContentFileName)) {
                    downloadedBackupContentsGraph = parser.parse(serializedGraph,
                            SupportedFormat.N_TRIPLE, null);
                } else {
                    Graph deserializedGraph = parser.parse(serializedGraph,
                            SupportedFormat.N_TRIPLE, null);
                    extractedTc.put(entryName, deserializedGraph);
                }
                baos.flush();
                baos.close();
View Full Code Here

    @Override
    public Graph createGraph(UriRef name, TripleCollection triples) {
        for (WeightedTcProvider provider : providerList) {
            try {
                Graph result = provider.createGraph(name, triples);

                // unregisters a possible Graph or MGraph service under this name
                // provided by a WeightedTcProvider with a lower weight.
                tcDisappears(name);
                mGraphCache.put(name, new MGraphHolder(provider, null));
View Full Code Here

            }
        } else {
            mode = "append";
        }
        InputStream is = new ByteArrayInputStream(graph);
        Graph parsedGraph = parser.parse(is, mediaType.toString());
        UriRef graphUri = new UriRef(graphName);
        LockableMGraph mGraph;
        boolean newGraph = false;
        try {
            mGraph = tcManager.getMGraph(graphUri);
View Full Code Here

     * @return the resulting MGraph or null if the RDF serialization format is not supported by the parser
     */
    public MGraph readModel(InputStream in, String format) {
        Parser parser = Parser.getInstance();
        if (parser.getSupportedFormats().contains(format)) {
            Graph graph = parser.parse(in, format);
            MGraph model = new SimpleMGraph(graph);
            return model;
        } else {
            log.warn("Unsupported RDF format: {}\nSupported RDF formats: {}",
                    format, parser.getSupportedFormats());
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.Graph

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.