Lat/long to postcode with OS Open Data / SPARQL - geolocation

I have the following, which retrieves the lat/long when given a postcode.
How can I do the reverse (give lat/long, retrieve postcode) in SPARQL?
PREFIX pc: <http://data.ordnancesurvey.co.uk/ontology/postcode/>
PREFIX pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?lat ?long
WHERE {
<http://data.ordnancesurvey.co.uk/id/postcodeunit/S24SU> pos:lat ?lat .
<http://data.ordnancesurvey.co.uk/id/postcodeunit/S24SU> pos:long ?long .
}
enter code here
http://data.ordnancesurvey.co.uk/datasets/os-linked-data

SPARQL is all about graph pattern matching. In your existing query, ?lat and ?long are variables, and you're looking for values for them. If you have a latitude and longitude already, you can can just put them into your query and replace the place with a variable. E.g.:
PREFIX pc: <http://data.ordnancesurvey.co.uk/ontology/postcode/>
PREFIX pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?place
WHERE {
?place pos:lat <your-lat-here> .
?place pos:long <your-long-here> .
}
You just need to replace &langle;your-lat-here&rangle; and &langle;your-long-here&rangle; with the kind of values that you get as results to your original query.

Related

Does SelectBuilder prevents sparql injection?

We are trying to prevent the sparql injection attacks in our application.To generate sparql queries we have used apache jean query builder classes(org.apache.jena.arq.querybuilder).
Is it enough to prevent the injection attacks?
We have tried by injecting the multiple triples instead of literal, query does not return any data. So does it mean query builder classes prevent injection?
String username="admin\". ?subject ?p ?o . ?subject <urn:publicid:property;name> \"admin";
SelectBuilder sb = new SelectBuilder().addVar( "*" ).addWhere( "?s", RDF.type, Namespace.USER_META_TYPE )
.addWhere( "?s", Namespace.USER_NAME, username );
I expect the resultset should be empty same thing has happened.
The addWhere( s, p, o ) method checks each object (s, p, or o) for type. In the case of strings it calls the org.apache.jena.sparql.util.NodeFactoryExtra method public static Node parseNode(String nodeString, PrefixMap pmap) method. This means that strings that
start with '<' and and with '> are converted to URIs.
start with "_:" are converted to anonymous nodes.
start with " or '' are strings
start with "?" are converted to variable type nodes.
contain only digits and '.' are converted to numeric literal node types.
are of the form prefix:localName where prefix is in the prefix map and localName is a valid localName are converted to URIs.
All other values are returned as strings.
This means that there is not a risk of injection in either QueryBuilder or UpdateBuilders.

string manipulation in Dart / flutter

I am parsing an RSS feed that
returns has the title in this format:
<title>Some Data with spaces / Bahnofstrasse 22</title>
so the first thing I did is to replace the spaces with a +
String result = _items[index].title.replaceAll(new RegExp(r"\s+\b|\b\s"), "+");
however, what I need to do is to select only the text after the / so in this case Bahnofstrasse 22, remove the spaces and add a city (e.g. Zurich) before the address so the desired results would be
Zürich,Bahnofstrasse,22
so essentially select all text after /, add Zurich and replace spaces with ,
If you know that the data will always be separated by a /, you could look at the second element of the split. For example,
final result = "Zürich," +
_items[index].title
.split("/")[1]
.replaceFirst("<", "")
.trim()
.replaceAll(" ", ",");
Regular expressions would only really be useful if, for example, the format of the data were variable.

How to create a wireshark display filter with wildcard?

Suppose I have a pattern like
01:02:(anything):04:05
How can I construct a display filter in wireshark to filter it out?
Must I do this?
data[0:2]==01:02 and data[3:2]==04:05
To use wildcard, you may use . (dot).
Both the searches below will give same result,
data.data ~ "Hello World"
data.data ~ He..o.Wor.d
In your case 01:02:(anything):04:05, if we do not know length of (anything) this may not work.
You can use the matches operator. This allows you to define regular expression matches. Consider this:
eth.dst matches "\xff.*\xff"
This will look for ethernet destination addresses that have a 0xFF followed by something (or nothing) and another 0xFF within it. So for your case, you could do:
eth.addr matches "\x01\x02.*\x04\x05"
This will look for those byte sequences in either the source or destination MACs. You could refine it more by using a byte count if you wanted to.
If you are not sure how many letter are in between the string you can use below filter
data.data ~ Hel.{1,}rld
or
data.data matches Hel.{1,}rld
here .{1,} means 1 or more characters in between & the letter should start from hel (in between anything) than ends with rld

How to escape search strings in TFS Code Search

Really loving the 'new' code search feature of TFS, but I am unable to guess how to escape " an ..
I want to find places in my code where I am using "SOMESTRING." in my code, but when searching for this the search engine seems to strib " and . so that I get all results where SOMESTRING is used and that particular string that is a lot of results.
I have tried with backslash eg. \"SOMESTRING.\" but same thing happens. ´strlit:SOMESTRING.` insures that I only get string literals in the results but the ´.´ is still ignored. The help don't seem to cover this.
Checked for some characters in code search.
You can't use the symbol characters except * and ? as part of your search query, which including below characters: . , : ; / \ ` ' " = ! # $ & + ^ | ~ < > ( ) { } [ ]. The search will simply ignore these symbols.
But you can use wildcard characters * and ? to broaden your search.
You can use wildcard characters anywhere in your search string except
as a prefix in a simple search string or a query that uses a code
type filter. For example, you cannot use a search query such as
*RequestHandler or class:?RequestHandler. However, you can use prefix wildcards with the other search filter functions; for example,
the search query strings file:*RequestHandler.cs and repo:?Handlers
are valid.
Please see Broaden your search with wildcards for details.
If you want to search the strings including these symbol exactly, you can first search it in code search, the copy the specific code to text editor (eg, Notepad++), then search stings with the symbol characters.

Double operations with FR or UK typed double

Description
If you want to store FR typed double in a node, you can only do it using String value, because double values are displayed like this: 12,58 (instead of 12.58 for US type).
So, if you want to do some computing in a cypher query, it's hard to use FR types doubles since they are String, and String + String results in a concatenation, not a real addition.
Example
To check this problem, you can simply create two nodes:
CREATE (a:TestNode{value : "12,45"}), (b:TestNode{value : "15"})
RETURN (a.value + b.value) AS result
Solutions ?
The obvious solution would be to store everything as double in the base, and do the computing on Java side, but it requires too much refactoring, and the problem is that some values are stored as FR double (like 1254,7898), some are stored as UK double (like 12,789.45) and some as US double (those ones are stored using the primitive type double).
I'm looking for a pure Cypher solution, to avoid massive data and code refactoring.
Interesting question. You can handle the differently formatted doubles in a CASE expression. First, you convert it to a string. If it contains both . and , it's UK. Else if it contains , but not . it's FR. Else it should be a native double. You can then replace the , and convert to float.
MATCH (a:TestNode)
RETURN
CASE
// UK formatted, 12,3456.45
WHEN toString(a.value) =~ ".*\\..*" AND toString(a.value) =~ ".*\\,.*"
// remove , and convert to float
THEN toFloat(replace(toString(a.value), ',', ''))
// FR formatted 1234,23
WHEN toString(a.value) =~ ".*\\,.*" AND NOT toString(a.value) =~ ".*\\..*"
// replace, with . and convert to float
THEN toFloat(replace(toString(a.value), ',', '.'))
// else it should be a double
ELSE toFloat(a.value)
END
But this query can only RETURN the value as a float/double. I don't know how you can include the CASE thing in a more complex query.

Resources