mff-uk / odcs

ODCleanStore
1 stars 11 forks source link

SPARQL Transformer - delete+insert sparql update #890

Closed tomas-knap closed 10 years ago

tomas-knap commented 10 years ago

Jirka, please test SPARQL transformer with a query of type:

PREFIX s: http://schema.org/

DELETE {?address s:geo ?geo} INSERT {?place s:geo ?geo} WHERE { ... }

I suspect that method AddGraphToUpdateQuery (see below) is not working properly - the named graph is not properly added.

Jirko, kdybys spravne osertril else vetev, tak bys videl, ze to mas blbe. Pomalu mi take dochazi trpelivost, nerad bych videl dalsi podobny prehmat. Tedy projdi si prosim ve svem volnem casu svuj kod a pridej testy tak, abys otestoval vsechny sve metody. Oprav prosim co nejdrive.

private String AddGraphToUpdateQuery(String updateQuery) {

    if (repository instanceof SailRepository) {
        return updateQuery;
    }

    String regex = "(insert|delete)\\s\\{";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(updateQuery.toLowerCase());

    boolean hasResult = matcher.find();
    boolean hasWith = updateQuery.toLowerCase().contains("with");

    if (hasResult && !hasWith) {

        int index = matcher.start();

        String first = updateQuery.substring(0, index);
        String second = updateQuery.substring(index, updateQuery.length());

        String graphName = " WITH <" + graph.stringValue() + "> ";

        String newQuery = first + graphName + second;
        return newQuery;

    } else {

        regex = "(insert|delete)\\sdata\\s\\{";
        pattern = Pattern.compile(regex);
        matcher = pattern.matcher(updateQuery.toLowerCase());

        hasResult = matcher.find();

        if (hasResult) {

            int start = matcher.start();
            int end = matcher.end();

            String first = updateQuery.substring(0, start);
            String second = updateQuery.substring(end, updateQuery.length());

            String myString = updateQuery.substring(start, end);
            String graphName = myString.replace("{",
                    "in graph <" + graph.stringValue() + "> {");

            String newQuery = first + graphName + second;

            return newQuery;

        }
    }
    return updateQuery;

}
tomas-knap commented 10 years ago

As a result, there is no graph specified, so the data is delete from a default graph and inserted to a default graph!