I have built this SPARQL Query:
String query_splInfo =
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>"+"\n"+
"SELECT ?name"+"\n"+
"WHERE {?x foaf:name ?name . " +
"FILTER regex(?name, \"Studienprogrammleitung Informatik\")}";
Jena returns an error message:
Failed: com.hp.hpl.jena.query.QueryParseException: Encountered " "regex" "regex "" at line 4, column 73.
Was expecting one of:
"graph" ...
"optional" ...
"filter" ...
"{" ...
"}" ...
";" ...
"," ...
"." ...
Please help me.
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>"+"\n"+
"SELECT ?name"+"\n"+
"WHERE {?x foaf:name ?name . "+"\n"+
"FILTER regex(?name, \"Studienprogrammleitung Informatik\")}";
Related
I'm trying to make this description generator, and I can't seem to make the first part work for one of the IF arguments as it does with the rest. It only checks the logical expression but doesn't bring the rest of the text body in the cell joined with & as it does in the case of the other IF arguments I have there linked one after the other. This example should make more sense.
try:
=INDEX(REGEXREPLACE(SUBSTITUTE(SUBSTITUTE(TRIM(FLATTEN(QUERY(TRANSPOSE(IF(IFERROR(
SPLIT(B1:B, CHAR(10)))="",,REGEXREPLACE({"", SEQUENCE(1, 100)}&". "&IFNA(VLOOKUP(
TRIM(SPLIT(B1:B, CHAR(10))),
{"ck", "click >";
"box", "select box";
"scd", "scroll down >"}, 2, 0),
SPLIT(B1:B, CHAR(10))), " ", CHAR(13)))),,9^9))),
" ", CHAR(10)), CHAR(13), " "), "^\. !?", ))
demo sheet
The first If statement encloses all the rest of the formula so if the regex matches "ck" the condition is satisfied, you get "click >" but nothing else happens. I think you can just move the final bracket so it is just after "select " like this:
=IF(REGEXMATCH(B4, "ck"),"click >",IF(REGEXMATCH(B4, "scd"),"scroll down > ",IF(REGEXMATCH(B4, "!"),"","select "))) & ARRAYFORMULA(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(TEXTJOIN(CHAR(10), 1, IF(REGEXMATCH(""&
SPLIT(B4, CHAR(10)), "^>.*"),
SPLIT(B4, CHAR(10)), TRANSPOSE(MMULT(TRANSPOSE(TRANSPOSE((SEQUENCE(1, COLUMNS(
SPLIT(B4, CHAR(10))))<=SEQUENCE(COLUMNS(
SPLIT(B4, CHAR(10))), 1, 0))*NOT(REGEXMATCH(
SPLIT(B4, CHAR(10)), "^>.+")))), TRANSPOSE(SIGN(NOT(REGEXMATCH(
SPLIT(B4, CHAR(10)), "^>.+"))))))&". "&
SPLIT(B4, CHAR(10)))), "^0. ", ),"scd",""),"ck",""),"!",""))
I have a client who is wanting the product search in the admin area to ignore the fact that there are special characters in the product names.
For example, they have a lot of products listed with the word “kings” or the word “king’s” with an apostrophe - both used correctly grammatically depending on the product.
What they want to be able to do is search for “kings” on the admin area and all products called “kings” and “king’s” appear - rather than just “kings” as it does by default.
They have the same problem with “remy” and “r.e.m.y” where, when searching for “remy” the search needs to ignore the fact that there are “.” In the name.
Opencart Version 2.3.0.2
Any help is greatly appreciated!
Look, if you have expirience you can do it easily, just find search query in Opencart and replace all special symbols with empty string, check this example if you have r.e.m.y in your database table blog, title column with value 'r.e.m.y, then this query will return you record
SELECT * FROM `blog` WHERE title = replace(title,'.','') = 'remy'
Check image for example:
Example is for points '.' only but you can do replace and for other special symbols.
Let me show you where to find this query:
First you can see link is catalog/product, so your controller is
in admin/catalog/product, when u type something in "title" input, it send GET parameter &filter_name to this controller. You can check the controller for that filter, see:
protected function getList() {
if (isset($this->request->get['filter_name'])) {
$filter_name = $this->request->get['filter_name'];
} else {
$filter_name = null;
}
Here it check for this GET parameter and set it to variable $filter_name, then bellow the code it send this variable to model:
$filter_data = array(
'filter_name' => $filter_name,
'filter_model' => $filter_model,
'filter_price' => $filter_price,
'filter_quantity' => $filter_quantity,
'filter_status' => $filter_status,
'filter_image' => $filter_image,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
'limit' => $this->config->get('config_limit_admin')
);
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
It set array with variables then u call $this->model->catalog->product->getTotalProducts, so there is query u need:
public function getTotalProducts($data = array()) {
$sql = "SELECT COUNT(DISTINCT p.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)";
$sql .= " WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
if (!empty($data['filter_name'])) {
$sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
}
if (!empty($data['filter_model'])) {
$sql .= " AND p.model LIKE '" . $this->db->escape($data['filter_model']) . "%'";
}
if (isset($data['filter_price']) && !is_null($data['filter_price'])) {
$sql .= " AND p.price LIKE '" . $this->db->escape($data['filter_price']) . "%'";
}
if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
$sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'";
}
if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
$sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
}
if (isset($data['filter_image']) && !is_null($data['filter_image'])) {
if ($data['filter_image'] == 1) {
$sql .= " AND (p.image IS NOT NULL AND p.image <> '' AND p.image <> 'no_image.png')";
} else {
$sql .= " AND (p.image IS NULL OR p.image = '' OR p.image = 'no_image.png')";
}
}
$query = $this->db->query($sql);
return $query->row['total'];
}
If you don't have expirience with Opencart it will be not so easy, but it's possible.
One hint: u can use your own query if this parameter is set (if-else) :)
I'm trying to parse a string into a flat list in TCL.
The string has the format of
name1='value1',name2='value2',name3='value3'
I'm wondering if there's a way to capture names and values into a list that looks like this:
{name1 value1 name2 value2 name3 value3}
Note that the name or value itself may contain anything which includes characters like ' or = or ,
well, possible
set data {name1='value1',name2='value2',name3='value3'}
foreach {- key value -} [regexp -all -inline {(.*?)='(.*?)'(,|$)} $data] {
lappend result $key $value
}
Note: If the key only occurs once, i suggest using dicts (dict set result $key $value).
The easiest way is to replace the symbols =, , and ' with spaces:
% set s {name1='value1',name2='value2',name3='value3'}
name1='value1',name2='value2',name3='value3'
% set new_s [string map {"='" " " "'," " " "'" " "} $s]
name1 value1 name2 value2 name3 value3
string map takes two parameters. The first is a list of old-new pairs of strings. The second is the string itself. Essentially, string map will search for the old strings and replace them with the new. For example, it will search for =' and replaces with (space).
Update
The above solution assumes no space in the names or values. The following solution will work for those values with embedded spaces:
% set s {name1='value1',name2='value 2',name3='value3'}
name1='value1',name2='value2',name3='value3'
% string map {"=" " " "'" {"} "," " "} $s
name1 "value1" name2 "value 2" name3 "value3"
You can do it with a negative character class
set s {name1='value1',name2='value2',name3='value3'}
set result [regexp -inline -all -- {[^=',]+} $s]
I am trying to create a module for parsing vim files which are sectioned in a specific manner. A sample file:
" My section {
set nocompatible " be iMproved
set encoding=utf-8
" }
" vim: set foldmarker={,} foldlevel=0 foldmethod=marker:
While writing the module, I've got stuck at this point:
module Vimrc =
autoload xfm
let section = del "\" " "\" " . key /[^\n]+/ . del "\n" "\n" . store /.*/ . del "\" " "\" "
let lns = [ section . del "\n" "\n" ] *
let filter = (incl "*.vim")
let xfm = transform lns filter
I'm aware that there are some other mistakes, but it complains about the regex key /[^\n]+/, saying:
/tmp/aug/vimrc.aug:3.36-.48:exception: The key regexp /[^ ]+/ matches
a '/'
I do not understand what the / character has got to do with this.
As the error says, your key regexp matches a slash, which is illegal since / is used as a level separator in the tree.
If your section names can contain slashes, you need to store them as a node value, not label, so instead of:
{ "My section"
{ "set" = "nocompatible" { "#comment" = "be iMproved" } } }
you'll have to do:
{ "section" = "My section"
{ "set" = "nocompatible" { "#comment" = "be iMproved" } } }
I like to list all drugs that start with some letter to fill autocomplete text box.Here is the code
public string[] GetCompletionList(string prefixText)
{
string rdfDat = AppDomain.CurrentDomain.BaseDirectory + "DrugRDF.rdf";
List<string> list = new List<string>();
TripleStore store = new TripleStore();
Graph rdf = new Graph();
FileLoader.Load(rdf, rdfDat, new RdfXmlParser());
store.Add(rdf);
string tmp = "^" + prefixText;
string sparqlQuery = "PREFIX mojLek: <http://www.example.org/mojLek#>"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
+ "SELECT ?x"
+ "WHERE {?h mojLek:ime ?x ."
+ "FILTER regex(str(?x),"+tmp+") }";
SparqlQueryParser sparqlParser = new SparqlQueryParser();
SparqlQuery query = sparqlParser.ParseFromString(sparqlQuery);
Object results = store.ExecuteQuery(query);
if (results is SparqlResultSet)
{
SparqlResultSet r = results as SparqlResultSet;
foreach (SparqlResult res in r)
{
list.Add(res["x"].ToString().ToLower());
}
}
return list.ToArray();
}
However if I try it with for example A there are already couples that starts with A I got this error
VDS.RDF.Parsing.RdfParseException: [Line 1 Column 263] The value 'A' is not valid as a QName
at VDS.RDF.Parsing.Tokens.SparqlTokeniser.TryGetQNameOrKeyword()
at VDS.RDF.Parsing.Tokens.SparqlTokeniser.GetNextToken()
at VDS.RDF.Parsing.Tokens.TokenQueue.InitialiseBuffer()
at VDS.RDF.Parsing.SparqlQueryParser.ParseInternal(SparqlQueryParserContext context)
at VDS.RDF.Parsing.SparqlQueryParser.ParseInternal(TextReader input)
at VDS.RDF.Parsing.SparqlQueryParser.ParseFromString(String queryString)
at SuggestWebService.GetCompletionList(String prefixText) in d:\Suggest\App_Code\SuggestWebService.cs:line 57
Put newlines in the query string to make the error messages better.
There are no SPARQL quotes at
regex(str(?x),"+tmp+")
Try:
regex(str(?x),'"+tmp+"')
which puts single quotes into the SPARQL. Be careful of any quotes in tmp.
I have changed my code in this way so it worked for me
string tmp="^"+prefixText;
var query = "PREFIX mojLek: <http://www.example.org/mojLek#>"
+ "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
+ "PREFIX fn: <http://www.w3.org/2005/xpath-functions#>"
+ "SELECT ?x ?h"
+ "WHERE {?h mojLek:ime ?x ."
+ "FILTER regex(?x,\""+tmp+"\")"
+"}";