query wikidata cities names in arabic and english - wikidata

I need to get cities names in arabic and english from wikidata
also after that I need to get states names in arabic and english
is it available to download the query return data or copy it to excel or csv?

if you want to use Wikidata Query Service and receive labels in mutliple languages at the same time you have to repeat the rdfs:label Statement for each language like
SELECT * WHERE {
?item (wdt:P31/(wdt:P279*)) wd:Q515;
rdfs:label ?cityLabelEN.
FILTER((LANG(?cityLabelEN)) = "en")
?item rdfs:label ?cityLabelAR.
FILTER((LANG(?cityLabelAR)) = "ar")
}
LIMIT 10
Try It
If you want to get states instead of cities: change the first object from wd:Q515 to wd:Q7275 (and adopt the variabelname for the labels)

Related

Search string which contains multiple words using CATSEARCH query in PL/SQL

String record : Blueoba Mountain Company
SQL Query :
SELECT from table
WHERE CATSEARCH(account_partner_name_type,'%Blueoba% %Mountain% %Company%', NULL) > 0)
where rn <=500;
If I write the full name of the string in the query (i.e.%Blueoba% %Mountain% %Company%) then it gives me the record.
But if I write %Blueoba% %Mountain% %Comp% or %Blue% %Company% or %Comp% then its not returning any record.
So ideally, if I write a word %comp% then it should search all the records which contains 'comp' word and show the records but its not showing.
Can anybody suggest something?
You can try using wild card characters
SELECT * from table
WHERE account_partner_name_type like '%Blueoba%'
and rn <=500;

sql where closure with modified column value

I have a master table containing URLs:
CREATE TABLE IF NOT EXISTS MasterTable (url, masterId, PRIMARY KEY(url), UNIQUE(masterId));
An url string looks like this: file:///Users/user1/Pictures/rubus_and_apple.jpeg.
Now I want to lookup on the url column but only on the filename rubus_and_apple and not on all url string. (Meaning only on the last component of the url w/o extension).
For example I want to look the keyword rubus and get the url:file:///Users/user1/Pictures/rubus_and_apple.jpeg.
I need my query to be like:
SELECT masterId
FROM MasterTable
WHERE <url last component w/o extension> LIKE '%/rubus%';
How can I do so?
You could use LIKE:
SELECT masterId
FROM MasterTable
WHERE url LIKE '%/rubus.%';
Please note that this expression is not-SARGable so it won't use index.
EDIT:
WITH MasterTable(MasterId, url) AS(
VALUES(1, 'file:///Users/user1/Pictures/rubus_and_apple.jpeg')
)
SELECT *
FROM MasterTable
WHERE REPLACE(url,RTRIM(url,REPLACE(url,'/','')),'') LIKE '%' || 'rubus' || '%';
-- part of string after last /
db<>fiddle demo

while inserting i can insert danish character in proper format in sqlite Db but while retrieving my query returns no result

while inserting i can insert danish character in proper format in sqlite Db but while retrieving my query returns no result
String searchQuery= "SELECT * FROM article,product where article.ItemNo=product.ItemNo ";
if(searchText.length()>0)
{
searchQuery += " AND (article.itemNo like '"+ searchText +"%' OR product.Description like '"+ searchText +"%')";
}
in debug mode query is
`SELECT * FROM article,product where article.ItemNo=product.ItemNo AND (article.itemNo like '%ø%' OR product.Description like '%ø%')..`
No result returns
Proper query will be
SELECT * FROM article,product where article.ItemNo=product.ItemNo AND (article.itemNo like '%Ø%' OR product.Description like '%Ø%');
the desired description field value in Db is MØNTPUNG.
I am wondering is there any issue of case sensitivty?I am using UTF8 encoding for my raw file that will insert data to DB.
The documentation says:
SQLite only understands upper/lower case for ASCII characters by default. The LIKE operator is case sensitive by default for unicode characters that are beyond the ASCII range. For example, the expression 'a' LIKE 'A' is TRUE but 'æ' LIKE 'Æ' is FALSE.
To handle non-ASCII characters correctly, store an uppercase version of your string(s) in a separate column, and search in that with an uppercase search pattern.

how to sanitize data in sqlite3 column

I have a sqlite3 table with a column by the name Title, which stores the names of the some movies.
Table name - table1
Column name - Title
Examples data: "Casablanca" (1983) {The Cashier and the Belly Dancer (#1.4)}
I have another sqlite3 table with a column that stores movie titles.
Table name - table2
Column name - Title
Examples data: casa blanca
Both these tables were created using different datasets, and as such although the movie name is the same (casa blanca vs "Casablanca" (1983) {The Cashier and the Belly Dancer (#1.4)}), both are stored with extra text.
What i would like to do is to SANITIZE the already stored data in both the columns. By sanitization, I would like to strip the cell content of:
1. spaces
2. spl chars like !, ', ", comma, etc..
3. convert all to lower case
I hope with that atleast some level of matching can be had between both the columns.
My question is, how do i perform these sanitizations on data that is already stored in sqlite tables. I do not have an option to sanitize before loading, as i only have access to the loaded database.
I am using sqlite 3.7.13, and i am using sqlite manager as the gui.
Thank You.
This task is too specialized to be done in SQL only.
You should write simple Perl or Python script which will scan your table, read data row by row, scrub it to meet your requirements and write it back.
This is example in Perl:
use DBI;
my $dbh = DBI->connect("dbi:mysql:database=my.db");
# replace rowid with your primary key, but it should work as is:
my $sth = $dbh->prepare(qq{
SELECT rowid,*
FROM table1
});
while (my $row = $sth->fetchrow_hashref()) {
my $rowid = $row->{rowid};
my $title = $row->{title};
# sanitize title:
$title = lc($title); # convert to lowercase
$title =~ s/,//g; # remove commas
# do more sanitization as you wish
# ...
# write it back to database:
$dbh->do(
qq{
UPDATE table1
SET title = ?
WHERE rowid = ?
}, undef,
$title,
$rowid,
);
}
$sth->finish();
$dbh->disconnect();

SQLite full-text search with multiple tokens using a prepared statement

Given the following tables:
create table index(name text, docid int);
create virtual table docs using fts4();
The following query works as intended when querying for a single token (for example: march, or bad):
select name from index where docid in (select docid from docs where docs match ?)
But how can I query for more than one token (say, bad bed)? Binding the string bad bed directly does not work (always selects nothing), neither surrounding the placeholder or the string with double quotes, nor using AND to MATCH each token separetly (this last one throws an error).
Using intersect does work, but it's clunky and innefficient when searching for many tokens:
select name from index where docid in (
select docid from docs where docs match ?
intersect
select docid from docs where docs match ?
intersect
...
)
Each ? is paired with a single token.
You can use the concatenation operator || in sqlite. '' would be the empty string
SELECT * FROM table WHERE docs MATCH '' || ? || ' ' || ? || ' ' || ? || ''
Make sure there is a space between every token or an ' AND '.
Update
Actually it doesn't work. It seems there are tokenator issues with this approach. Its better to concatenate all the tokens with the space and bind the resulting string with a single '?'
There are operators within the match syntax in FTS so you can use AND, OR and NOT.
See here for documentation
e.g.
-- Return the docid values associated with all documents that contain the
-- two terms "sqlite" and "database", and/or contain the term "library".
SELECT docid FROM docs WHERE docs MATCH 'sqlite AND database OR library';

Resources