Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-2864: Fix algebra function name for the hash functions. #2865

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 115 additions & 124 deletions jena-arq/src/main/java/org/apache/jena/query/QueryFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,210 +25,201 @@
import org.apache.jena.irix.IRIx;
import org.apache.jena.riot.system.stream.StreamManager;
import org.apache.jena.shared.NotFoundException;
import org.apache.jena.sparql.lang.ParserARQ ;
import org.apache.jena.sparql.lang.SPARQLParser ;
import org.apache.jena.sparql.lang.SPARQLParserRegistry ;
import org.apache.jena.sparql.syntax.Element ;
import org.apache.jena.sparql.syntax.Template ;

public class QueryFactory
{
/** Create a SPARQL query from the given string.
import org.apache.jena.sparql.lang.ParserARQ;
import org.apache.jena.sparql.lang.SPARQLParser;
import org.apache.jena.sparql.lang.SPARQLParserRegistry;
import org.apache.jena.sparql.syntax.Element;
import org.apache.jena.sparql.syntax.Template;

public class QueryFactory {
/**
* Create a SPARQL query from the given string.
*
* @param queryString The query string
* @throws QueryException Thrown when a parse error occurs
* @param queryString The query string
* @throws QueryException Thrown when a parse error occurs
*/

static public Query create(String queryString)
{
return create(queryString, Syntax.defaultQuerySyntax) ;
static public Query create(String queryString) {
return create(queryString, Syntax.defaultQuerySyntax);
}

/** Create a query from the given string with the
/**
* Create a query from the given string with the
*
* @param queryString The query string
* @param syntax {@link Syntax}
* @throws QueryException Thrown when a parse error occurs
* @param queryString The query string
* @param syntax {@link Syntax}
* @throws QueryException Thrown when a parse error occurs
*/

static public Query create(String queryString, Syntax syntax)
{
return create(queryString, null, syntax) ;
static public Query create(String queryString, Syntax syntax) {
return create(queryString, null, syntax);
}

/** Create a query from the given string by calling the parser.
/**
* Create a query from the given string by calling the parser.
*
* @param queryString The query string
* @param baseURI Base URI
* @throws QueryException Thrown when a parse error occurs
* @param queryString The query string
* @param baseURI Base URI
* @throws QueryException Thrown when a parse error occurs
*/

static public Query create(String queryString, String baseURI)
{
Query query = new Query() ;
return parse(query, queryString, baseURI, Syntax.defaultQuerySyntax) ;
static public Query create(String queryString, String baseURI) {
Query query = new Query();
return parse(query, queryString, baseURI, Syntax.defaultQuerySyntax);
}

/** Create a query from the given string by calling the parser.
*
* @param queryString The query string
* @param baseURI Base URI
* @param syntax {@link Syntax}
* @throws QueryException Thrown when a parse error occurs
*/

static public Query create(String queryString, String baseURI, Syntax syntax)
{
Query query = new Query() ;
return parse(query, queryString, baseURI, syntax) ;
}
/**
* Create a query from the given string by calling the parser.
*
* @param queryString The query string
* @param baseURI Base URI
* @param syntax {@link Syntax}
* @throws QueryException Thrown when a parse error occurs
*/

/**
* Make a query - no parsing done
*/
static public Query create() { return new Query() ; }
static public Query create(String queryString, String baseURI, Syntax syntax) {
Query query = new Query();
return parse(query, queryString, baseURI, syntax);
}

/**
* Make a query - no parsing done
*/
static public Query create() {
return new Query();
}

/**
/**
* Make a query - no parsing done - old name: {@link #create()} preferred.
*/
static public Query make() { return create() ; }
static public Query make() {
return create();
}

/**
* Make a query from another one by deep copy (a clone).
* The returned query will be .equals to the original.
* The returned query can be mutated without changing the
* original (at which point it will stop being .equals)
*
* @param originalQuery The query to clone.
* Make a query from another one by deep copy (a clone). The returned query will
* be .equals to the original. The returned query can be mutated without changing
* the original (at which point it will stop being .equals)
*
* @param originalQuery The query to clone.
*/

static public Query create(Query originalQuery)
{
return originalQuery.cloneQuery() ;
static public Query create(Query originalQuery) {
return originalQuery.cloneQuery();
}

/** Parse a query from the given string by calling the parser.
/**
* Parse a query from the given string by calling the parser.
*
* @param query Existing, uninitialized query
* @param queryString The query string
* @param baseURI URI for relative URI expansion
* @param syntaxURI URI for the syntax
* @throws QueryException Thrown when a parse error occurs
* @param query Existing, uninitialized query
* @param queryString The query string
* @param baseURI URI for relative URI expansion
* @param syntaxURI URI for the syntax
* @throws QueryException Thrown when a parse error occurs
*/

static public Query parse(Query query, String queryString, String baseURI, Syntax syntaxURI)
{
static public Query parse(Query query, String queryString, String baseURI, Syntax syntaxURI) {
if ( syntaxURI == null )
syntaxURI = query.getSyntax() ;
syntaxURI = query.getSyntax();
else
query.setSyntax(syntaxURI) ;
query.setSyntax(syntaxURI);

SPARQLParser parser = SPARQLParser.createParser(syntaxURI) ;
SPARQLParser parser = SPARQLParser.createParser(syntaxURI);

if ( parser == null )
throw new UnsupportedOperationException("Unrecognized syntax for parsing: "+syntaxURI) ;
throw new UnsupportedOperationException("Unrecognized syntax for parsing: " + syntaxURI);

if ( query.getBase() == null )
{
if ( query.getBase() == null ) {
IRIx queryBase = null;
try {
queryBase = ( baseURI != null ) ? IRIs.resolveIRI(baseURI) : IRIs.getSystemBase();
queryBase = (baseURI != null) ? IRIs.resolveIRI(baseURI) : IRIs.getSystemBase();
} catch (Exception ex) {}
if ( queryBase == null )
queryBase = IRIx.create("http://localhost/query/defaultBase#");
query.setBase(queryBase);

}
return parser.parse(query, queryString) ;
return parser.parse(query, queryString);
}

static boolean knownParserSyntax(Syntax syntaxURI)
{
return SPARQLParserRegistry.get().containsFactory(syntaxURI) ;
static boolean knownParserSyntax(Syntax syntaxURI) {
return SPARQLParserRegistry.get().containsFactory(syntaxURI);
}


/**
* Read a SPARQL query from a file.
*
* @param url
* URL (file: or http: or anything a FileManager can handle)
* @param url URL (file: or http: or anything a FileManager can handle)
* @return A new query object
*/
static public Query read(String url)
{
return read(url, (StreamManager)null, null, null) ;
static public Query read(String url) {
return read(url, (StreamManager)null, null, null);
}

/** Read a SPARQL query from a file.
/**
* Read a SPARQL query from a file.
*
* @param url URL (file: or http: or anything a FileManager can handle)
* @param baseURI BaseURI for the query
* @return A new query object
* @param url URL (file: or http: or anything a FileManager can handle)
* @param baseURI BaseURI for the query
* @return A new query object
*/
static public Query read(String url, String baseURI)
{
return read(url, (StreamManager)null, baseURI, null) ;
static public Query read(String url, String baseURI) {
return read(url, (StreamManager)null, baseURI, null);
}

/** Read a query from a file.
/**
* Read a query from a file.
*
* @param url URL (file: or http: or anything a FileManager can handle)
* @param langURI Query syntax
* @return A new query object
* @param url URL (file: or http: or anything a FileManager can handle)
* @param langURI Query syntax
* @return A new query object
*/
static public Query read(String url, Syntax langURI)
{
return read(url, (StreamManager)null, null, langURI) ;
static public Query read(String url, Syntax langURI) {
return read(url, (StreamManager)null, null, langURI);
}

/** Read a query from a file.
/**
* Read a query from a file.
*
* @param url URL (file: or http: or anything a FileManager can handle)
* @param baseURI BaseURI for the query
* @param langURI Query syntax
* @return A new query object
* @param url URL (file: or http: or anything a FileManager can handle)
* @param baseURI BaseURI for the query
* @param langURI Query syntax
* @return A new query object
*/
static public Query read(String url, String baseURI, Syntax langURI)
{
return read(url, (StreamManager)null, baseURI, langURI) ;
static public Query read(String url, String baseURI, Syntax langURI) {
return read(url, (StreamManager)null, baseURI, langURI);
}

/** Read a query from a file.
/**
* Read a query from a file.
*
* @param url URL (file: or http: or anything a FileManager can handle)
* @param streamManager Optional StreamManager
* @param baseURI BaseURI for the query
* @param langURI Query syntax
* @return A new query object
* @param url URL (file: or http: or anything a FileManager can handle)
* @param streamManager Optional StreamManager
* @param baseURI BaseURI for the query
* @param langURI Query syntax
* @return A new query object
*/
static public Query read(String url, StreamManager streamManager, String baseURI, Syntax langURI)
{
static public Query read(String url, StreamManager streamManager, String baseURI, Syntax langURI) {
if ( streamManager == null )
streamManager = StreamManager.get() ;
streamManager = StreamManager.get();

InputStream in = streamManager.open(url);
if ( in == null )
throw new NotFoundException("Not found: "+url);
throw new NotFoundException("Not found: " + url);
String qStr = IO.readWholeFileAsUTF8(streamManager.open(url));
if ( baseURI == null )
baseURI = url ;
baseURI = url;
if ( langURI == null )
langURI = Syntax.guessFileSyntax(url) ;
langURI = Syntax.guessFileSyntax(url);

return create(qStr, baseURI, langURI) ;
return create(qStr, baseURI, langURI);
}


static public Element createElement(String elementString)
{
return ParserARQ.parseElement(elementString) ;
static public Element createElement(String elementString) {
return ParserARQ.parseElement(elementString);
}

static public Template createTemplate(String templateString)
{
return ParserARQ.parseTemplate(templateString) ;
static public Template createTemplate(String templateString) {
return ParserARQ.parseTemplate(templateString);
}
}
17 changes: 9 additions & 8 deletions jena-arq/src/main/java/org/apache/jena/sparql/expr/E_MD5.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

import static org.apache.jena.atlas.lib.Lib.uppercase;

import org.apache.jena.sparql.sse.Tags ;
import org.apache.jena.sparql.sse.Tags;

public class E_MD5 extends ExprDigest
{
private static final String symbol = uppercase(Tags.tagMD5) ;
public class E_MD5 extends ExprDigest {
private static final String symbol = Tags.tagMD5;
private static final String printName = uppercase(symbol);

public E_MD5(Expr expr)
{
super(expr, symbol, "MD5") ;
public E_MD5(Expr expr) {
super(expr, symbol, printName, "MD5");
}

@Override
public Expr copy(Expr expr) { return new E_MD5(expr) ; }
public Expr copy(Expr expr) {
return new E_MD5(expr);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import org.apache.jena.sparql.sse.Tags;

public class E_SHA1 extends ExprDigest {
private static final String symbol = uppercase(Tags.tagSHA1);
private static final String symbol = Tags.tagSHA1;
private static final String printName = uppercase(symbol);

public E_SHA1(Expr expr) {
super(expr, symbol, "SHA-1");
super(expr, symbol, printName, "SHA-1");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import org.apache.jena.sparql.sse.Tags;

public class E_SHA224 extends ExprDigest {
private static final String symbol = uppercase(Tags.tagSHA224);
private static final String symbol = Tags.tagSHA224;
private static final String printName = uppercase(symbol);


public E_SHA224(Expr expr) {
super(expr, symbol, "SHA-224");
super(expr, symbol, printName, "SHA-224");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
import org.apache.jena.sparql.sse.Tags;

public class E_SHA256 extends ExprDigest {
private static final String symbol = uppercase(Tags.tagSHA256);
private static final String symbol = Tags.tagSHA256;
private static final String printName = uppercase(symbol);

public E_SHA256(Expr expr) {
super(expr, symbol, "SHA-256");
super(expr, symbol, printName, "SHA-256");
}

@Override
Expand Down
Loading
Loading