org.apache.jena.atlas.lib.StrUtils Java Examples

The following examples show how to use org.apache.jena.atlas.lib.StrUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRDFChangesGraph.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
private Graph replay() {
    IO.close(bout);
    final boolean DEBUG = false;

    if ( DEBUG ) {
        System.out.println("== Graph ==");
        RDFDataMgr.write(System.out, baseGraph, Lang.NQ);
        System.out.println("== Replay ==");
        String x = StrUtils.fromUTF8bytes(bout.toByteArray());
        System.out.print(x);
        System.out.println("== ==");
    }

    // A completely separate graph (different dataset)
    Graph graph2 = txnGraph();

    try(ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray())) {
        RDFPatchOps.applyChange(graph2, bin);
        if ( DEBUG ) {
            System.out.println("== Graph outcome ==");
            RDFDataMgr.write(System.out, graph2, Lang.NT);
            System.out.println("== ==");
        }
        return graph2;
    } catch (IOException ex) { IO.exception(ex); return null; }
}
 
Example #2
Source File: ConfigurationImpl.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object reversePrefix(String str) {
	for (Iterator<Object> it = conf_prefix.keySet().iterator(); it.hasNext();) {
		String key = (String) it.next();
		if (str.indexOf(key) > -1)
			return StrUtils.replace(str, key, conf_prefix.get(key).toString());
	}

	return str;
}
 
Example #3
Source File: UpdateExecuteOperations.java    From xcurator with Apache License 2.0 5 votes vote down vote up
public static void ex2(Dataset dataset)
{
    // Execute a series of operations at once.
    // See ex3 for a better way to build up a request
    // For maximum portability, multiple operations should be separated by a ";".
    // The "\n" imporves readability and parser error messages.
    String cmd = StrUtils.strjoin(" ;\n",
                                  "DROP ALL",
                                  "CREATE GRAPH <http://example/g2>",   // Not needed for most datasets
                                  "LOAD <file:etc/update-data.ttl> INTO GRAPH <http://example/g2>") ;
    // check string created
    System.out.println(cmd) ;
    UpdateAction.parseExecute(cmd, dataset) ;
}
 
Example #4
Source File: ExTDB_Txn2.java    From xcurator with Apache License 2.0 5 votes vote down vote up
public static void main(String... argv)
{
    String directory = "MyDatabases/DB1" ;
    Dataset dataset = TDBFactory.createDataset(directory) ;

    // Start WRITE transaction. 
    //   It's possible to read from the datet inside the write transaction.

    //   An application can have other Datasets, in the same JVM, 
    //   tied to the same TDB database performing read
    //   transactions concurrently. If another write transaction
    //   starts, the call of dataset.begin(WRITE) blocks until
    //   existing writer finishes.
    
    dataset.begin(ReadWrite.WRITE) ;
    try
    {
        GraphStore graphStore = GraphStoreFactory.create(dataset) ;
        // Do a SPARQL Update.
        String sparqlUpdateString = StrUtils.strjoinNL(
             "PREFIX . <http://example/>",
             "INSERT { :s :p ?now } WHERE { BIND(now() AS ?now) }"
             ) ;

        execUpdate(sparqlUpdateString, graphStore) ;
        dataset.commit() ;
        // Or call .abort()
        
    } finally
    {
        // Notify the end of the transaction.
        // The transaction was finished at the point .commit or .abort was called.
        // .end will force an abort() if no previous call to .commit() or .abort()
        // has occurred, so .end() help manage track the state of the transaction.
        // .end() can be called multiple times for the same .begin(WRITE)
        dataset.end() ;
    }
}
 
Example #5
Source File: ConfigurationImpl.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String reverseRoot(String path) {
	if (path != null && path.indexOf("{ROOT}") > -1) {
		return StrUtils.replace(path, "{ROOT}", getRoot());
	}

	return path;
}
 
Example #6
Source File: ConfigurationImpl.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object reversePrefix(String str) {
	for (Iterator<Object> it = conf_prefix.keySet().iterator(); it.hasNext();) {
		String key = (String) it.next();
		if (str.indexOf(key) > -1)
			return StrUtils.replace(str, key, conf_prefix.get(key).toString());
	}

	return str;
}
 
Example #7
Source File: ConfigurationImpl.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String reverseRoot(String path) {
	if (path != null && path.indexOf("{ROOT}") > -1) {
		return StrUtils.replace(path, "{ROOT}", getRoot());
	}

	return path;
}
 
Example #8
Source File: ConfigurationImpl.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object reversePrefix(String str) {
	for (Iterator<Object> it = conf_prefix.keySet().iterator(); it.hasNext();) {
		String key = (String) it.next();
		if (str.indexOf(key) > -1)
			return StrUtils.replace(str, key, conf_prefix.get(key).toString());
	}

	return str;
}
 
Example #9
Source File: SPARQLExtFmtExprSPARQL.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(ExprAggregator eAgg) {
	final Aggregator agg = eAgg.getAggregator();
	if (agg instanceof AggCount) {
		out.print("COUNT(*)");
		return;
	}
	if (agg instanceof AggCountDistinct) {
		out.print("COUNT(DISTINCT *)");
		return;
	}
	out.print(agg.getName());
	out.print("(");
	String clazz = agg.getClass().getSimpleName();
	if (clazz.endsWith("Distinct")) {
		out.print("DISTINCT ");
	}
	if (agg.getExprList() != null) {
		SPARQLExtFmtUtils.fmtSPARQL(out, agg.getExprList(), context);
	}
	String separator = null;
	if (agg instanceof AggGroupConcat) {
		separator = ((AggGroupConcat) agg).getSeparator();
	}
	if (agg instanceof AggGroupConcatDistinct) {
		separator = ((AggGroupConcatDistinct) agg).getSeparator();
	}
	if (separator != null) {
		out.print(" ; SEPARATOR=");
		String y = StrUtils.escapeString(separator);
		out.print("'");
		out.print(y);
		out.print("'");
	}
	out.print(")");
}
 
Example #10
Source File: TestRDFChanges.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
@Test public void changes_write_read_05() {
    byte[] output = write(changes->{
        changes.txnBegin();
        changes.txnCommit();
    });
    assertNotEquals(0, output.length);
    String x = StrUtils.fromUTF8bytes(output);
    assertEquals("TX .\nTC .\n", x);
}
 
Example #11
Source File: DeltaLogging.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
/** Initialize log4j2 from a default (in XML non-strict format) */
private static void defaultLogging() {
    byte b[] = StrUtils.asUTF8bytes(getDefaultString());
    try (InputStream input = new ByteArrayInputStream(b)) {
        ConfigurationSource source = new ConfigurationSource(input);
        ConfigurationFactory factory = ConfigurationFactory.getInstance();
        Configuration configuration = factory.getConfiguration(null, source);
        Configurator.initialize(configuration);
    }
    catch (IOException ex) {
        IOX.exception(ex);
    }
}
 
Example #12
Source File: ConfigurationImpl.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String reverseRoot(String path) {
	if (path != null && path.indexOf("{ROOT}") > -1) {
		return StrUtils.replace(path, "{ROOT}", getRoot());
	}

	return path;
}
 
Example #13
Source File: ConfigurationImpl.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object reversePrefix(String str) {
	for (Iterator<Object> it = conf_prefix.keySet().iterator(); it.hasNext();) {
		String key = (String) it.next();
		if (str.indexOf(key) > -1)
			return StrUtils.replace(str, key, conf_prefix.get(key).toString());
	}

	return str;
}
 
Example #14
Source File: ConfigurationImpl.java    From SDA with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String reverseRoot(String path) {
	if (path != null && path.indexOf("{ROOT}") > -1) {
		return StrUtils.replace(path, "{ROOT}", getRoot());
	}

	return path;
}
 
Example #15
Source File: TestRDFChanges.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
@Test public void changes_write_read_04() {
    byte[] output = write(changes->{});
    assertEquals(0, output.length);
    String x = StrUtils.fromUTF8bytes(output);
}
 
Example #16
Source File: Zk.java    From rdf-delta with Apache License 2.0 4 votes vote down vote up
public static String zkFetchStr(CuratorFramework client, String path) {
    byte[] x = zkFetch(client, path);
    if ( x == null )
        return null;
    return StrUtils.fromUTF8bytes(x);
}
 
Example #17
Source File: TokenizerFactory.java    From RDFstarTools with Apache License 2.0 4 votes vote down vote up
public static Tokenizer makeTokenizerASCII(String string) {
    byte b[] = StrUtils.asUTF8bytes(string) ;
    ByteArrayInputStream in = new ByteArrayInputStream(b) ;
    return makeTokenizerASCII(in) ;
}