Filter SPARQL using Jena - filter

I have quiz game in which user have to answer questions like:
What is German capital city name? Options are:
Berlin
Madrid
London
The data are in my owl file. I have another ontology also in which I have rdfs:comment of resources (options of quiz questions) like rdfs:comment of Berlin, London etc.
I want if user choose the wrong option i-e London, rdfs:comment of right option should be displayed to user, Berlin in this case.
The right (correct) option I have is in java variable 'correct' and if user click wrong option, I want to show the rdfs:comment of correct option as:
"SELECT * " +
" WHERE { ?x rdfs:comment ?y " + "FILTER regex( ?y ,'"+correct+"' ) " +
"}";
But it does not give me the rdfs:comment of correct option when user clicked on wrong option.
Is there any problem in the query?

Related

Multi key in redis by spring boot

redisTemplate.opsForHash().get ("CAR", name);
so we get the car by name.
redisTemplate.opsForHash ().put ("CAR", "TOYOTA", "PRIUS");
This is how we write data to REDIS.
That is, using TOYOTA and CAR we can get PRIUS.
Now, I should understand how to record and find data by a pair of keys. For example, I should find a car not only by brand ("TOYOTA") but also by color.
redisTemplate.opsForHash () .put (" CAR "," TOYOTA "+" WHITE "," PRIUS ");
The question is how to use the second parameter?
redisTemplate.opsForHash (). get (" CAR ", name + color);
In my case, the pair name and color are unique and i need to search for them.
In case of searching by one value, everything works fine, but it is not clear how to search by two parameters.
thanks in advance
Just maintian different cars and cars with colors in the hash.
Map<String,String> map = new HashMap<>();
map.put("TOYOTA","PRIUS");
map.put("TOYOTA:WHITE","PRIUS-w");
map.put("TOYOTA:YELLOW","PRIUS-y");
redisTemplate.opsForHash().putAll("CAR",map);

Best way to define subpredicates with predicateEditor from users' perspective

I am wondering how to use NSPredicateEditor to define subpredicates from out the user's perspective - and how to implement it.
Suppose we have a simple NSPredicateEditor created in IB as shown below.
It has 2 items to choose from:
lastname
address.street
So we can create a predicate like
lastname ==[c] "Smith" OR lastname ==[c] "Miller" OR address.street ==[c] "3rd Avenue"
Now, if I want to have only Millers selected, living in the 3rd Avenue, what can I do ? I would prefer to have a button like "s" to create a subpredicate just below the selected line (Miller) to get this result:
lastname ==[c] "Smith" OR (lastname ==[c] "Miller" AND address.street ==[c] "3rd Avenue")
Unfortunately, there is no other button than + or - for each item (row).
Is there any other way ? Can it be done with low programmatically effort ?
Set "Nesting" of the predicate editor to "Compound". At runtime: Press the Option Key and the + button will change to … for adding a compound row.

How can I prioritize search country in Bing Maps Ajax

In current realization I just add country to query, but this logic is incorrect.
$.ajax({
url: 'https://dev.virtualearth.net/REST/v1/Locations/'
+ searchString + ' ' + currentCountry + '?c=' + currentCulture + ...,
dataType: 'script'
});
But if I try to search city out of currentCountry, I will find currentCountry, but not searchString .
Example: searchString = Boston, currentCountry = Australia
Second approach - remove currentCountry from query at all, but it will cause another bug.
I will not find less famous place in currentCountry
Example: searchString = Moscow, currentCountry = USA.
Result of this query will be - Moscow, Russia and not Moscow, Washington, D.C.
Is there some ability to specify search country?
First try of search will be in currentCountry, if it fails, then second will be in all World.
If you read the best practices for Bing Maps it actually recommends using the unstructured URL format rather than the structured format when geocoding as it will increase the accuracy of the results: https://msdn.microsoft.com/en-us/library/dn894107.aspx
In order to limit the results to a single country, simple append the country to the query.
Your code is close but there should be a comma, and you would be using the query parameter as the format you are using is meant for reverse geocoding coordinates. Here is a modified version of your code:
$.ajax({
url: 'https://dev.virtualearth.net/REST/v1/Locations?q='
+ encodeURIComponent(searchString + ', ' + currentCountry) + '?c=' + currentCulture + ...,
dataType: 'script'
});
You also want to encode the query value to ensure that special characters do not cause any issues.
According to Find a Location by Address you could get the latitude and longitude coordinates based on a set of address values for specific countries.
Example:
The query:
http://dev.virtualearth.net/REST/v1/Locations/US/Moscow?o=xml&key=BingMapsKey
Note: A structured URL specifies the location data for the country
(US in this example) as part of the URL path.
will return locations for Moscow situated in United States.

Map Reduce output show decimal number in format 5.7491844E7 etc

My Java Mapreduce output shows me number in format 5.7491844E7 etc , Please let me know how can I get the correct result printed ?
Output:
Baby 5.7491844E7
Books 5.7450452E7
CDs 5.7410388E7
Cameras 5.7299596E7
Children's Clothing 5.7625016E7
Computers 5.7314756E7
Consumer Electronics 5.7453124E7
Crafts 5.7418584E7
DVDs 5.7649004E7
Garden 5.7539812E7
Health and Beauty 5.7480924E7
Men's Clothing 5.7621152E7
Music 5.749592E7
Pet Supplies 5.7197412E7
Sporting Goods 5.75983E7
Toys 5.7464028E7
Video Games 5.7513068E7
Women's Clothing 5.7434656E7
You can use any of the below options
decimalFormat.
DecimalFormat df = new DecimalFormat("#");
df.setMaximumFractionDigits(8);
System.out.println(df.format(value));
printf.
System.out.printf("%.9f", value);
System.out.println();
convert toBigDecimal and toPlainString().
System.out.println(new BigDecimal(value).toPlainString());
System.out.println();
String.format
System.out.println(String.format("%.12f", value));

ASP Classic SQL Query error message, right syntax please

I am passing two (2) parameters in the URL, and building the following SQL:
mQry = "SELECT DISTINCT name FROM link3 WHERE invoice_num =" & request.querystring("num") & "AND name LIKE" & request.querystring("nam")
I got an error message:
Microsoft OLE DB Provider for Oracle error '80040e14'
ORA-00933: SQL command not properly ended
What would be the right syntax for this?
You need to put quotes around the LIKE clause. Also, you could consider using percents for wildcard matching
mQry = "SELECT DISTINCT name FROM link3 WHERE invoice_num =" & request.querystring("num") & " AND name LIKE '%" & request.querystring("nam") & "%' "
Part of your problem may be the improper spacing around the quotes where you're inserting the values. This:
mQry = "SELECT DISTINCT name FROM link3 WHERE invoice_num =" & request.querystring("num") & "AND name LIKE" & request.querystring("nam")
Will most likely result in sending this to the database:
SELECT DISTINCT name
FROM link3
WHERE invoice_num =2AND name LIKEsomeothervalue
If you add proper spacing like this:
mQry = "SELECT DISTINCT name FROM link3 WHERE invoice_num = " & request.querystring("num") & " AND name LIKE " & request.querystring("nam")
It would give you a more properly formatted result like this:
SELECT DISTINCT name
FROM link3
WHERE invoice_num = 2 AND name LIKE someothervalue
Any time I get errors that indicate problems with SQL formatting/structure I tend to log the SQL that is sent before it goes to the database. This helps spot odd issues like that.
Also, sharpguru is probably right - the LIKE clause probably isn't formatted correctly either. You need to enclose text values in single-quotes, and the % is a wildcard matching 0 or more characters - making this more like what you are probably looking for:
mQry = "SELECT DISTINCT name FROM link3 WHERE invoice_num = " & request.querystring("num") & " AND name LIKE '%" & request.querystring("nam") & "%'"
Now, this does all assume that invoice_num is some sort of numeric value - which is implied in your question and code. However, if it is not (as suggested by your comment and other questions), you would need to put the value in single quotes - just like any other text field in almost all RDBMSs:
mQry = "SELECT DISTINCT name FROM link3 WHERE invoice_num = '" & request.querystring("num") & "' AND name LIKE '%" & request.querystring("nam") & "%'"
The above would also be used if the data type of the database column invoice_num was set to a non-numeric data type. Just because the data is somehting that could be called numeric, doesn't mean it's automatically treated as numeric. If the data type of the column is text, ntext, or any other non-numeric type, then you will need to surround the value in quotes just like any other text value.
And, while not related to the question, I'm hoping this is an over-simplified example and you're not directly inserting QueryString values into the SQL statement. If you haven't been told yet, that's opening you up to a wide variety of security problems - look up some information on SQL Injection.

Resources