I got a TSV file that I'm converting with tarql.
Column prop has strings like dc:source, skos:broader etc. How can I convert these to the corresponding URLs? Assume I have all needed prefixes defined in the tarql query.
I can do this statically eg uri(concat(str(dc:),"source")) but how to do it dynamically? The problem can be narrowed to this: given a prefix dc: how to expand it to the appropriate URL?
Looked at ARQ functions but didn't find anything appropriate. If there's no other solution, I can use a VALUES table that repeats the prefixes and namespaces, but what an ugly solution...
The tarql:expandPrefixedName(?qname) function (completely coincidentally committed just today) does exactly what you need: It expands a prefixed name to a full IRI, using any prefixes declared in the query.
The tarql namespace is declared implicitly in every Tarql query.
Related
I am using Directory.GetDirectories() to get a list of folders that meet a certain criteria by using its searchPattern parameter.
I am only looking for any folders containing a specific word, say alphabet, my code is as follows:
Directory.GetDirectories(rootToSearch, "*alphabet*")
But, there is a common abbreviation that I know to expect for this word, say abc. If I was searching in Windows File Explorer I could search for *alphabet* OR *abc* and it would work as expected, however putting this as the searchPattern results in the function finding no folders, presumably because it is taking it as one search term including OR as a literal, instead of 2 terms delineated with OR.
Is there any way to achieve an OR statement in the search pattern? The MSDN says:
The search string to match against the names of subdirectories in path. This parameter can contain a combination of valid literal and wildcard characters, but it doesn't support regular expressions.
So I know that I can't use Regular Expressions. I tried using |, but that results in an Illegal characters in path error.
As per this question you can use LINQ to filter an array of all directories on the root, instead of using the searchPattern
But that question used GetFiles() and there are certain things to take into account when using the solution for GetDirectories()
To ensure that your search pattern is indeed being used only against the folder name rather than the entire path, use DirectoryInfo
LCase() is also used to mimic GetDirectories() accordingly.
Dim folders = Directory.GetDirectories(rootToSearch) _
.Where(Function(s)
Return LCase(New DirectoryInfo(s).Name).Contains("abc") Or LCase(New DirectoryInfo(s).Name).Contains("alphabet")
End Function)
I have review multiple instructions on URL-parameters which all suggest 2 approaches:
Parameters can follow / forward slashes or be specified by parameter name and then by parameter value. so either:
1) http://numbersapi.com/42
or
2) http://numbersapi.com/random?min=10&max=20
For the 2nd one, I provide parameter name and then parameter value by using the ?. I also provide multiple parameters using ampersand.
Now I have see the request below which works fine but does not fit into the rules above:
http://numbersapi.com/42?json
I understand that the requests sets 42 as a parameter but why is the ? not followed by the parameter name and just by the value. Also the ? seems to be used as an ampersand???
From Wikipedia:
Every HTTP URL conforms to the syntax of a generic URI. The URI generic syntax consists of a hierarchical sequence of five components:
URI = scheme:[//authority]path[?query][#fragment]
where the authority component divides into three subcomponents:
authority = [userinfo#]host[:port]
This is represented in a syntax diagram as:
As you can see, the ? ends the path part of the URL and starts the query part.
The query part is usually a &-separated string of name=value pairs, but it doesn't have to be, so json is a valid value for the query part.
Or, as the Wikipedia articles says it:
An optional query component preceded by a question mark (?), containing a query string of non-hierarchical data. Its syntax is not well defined, but by convention is most often a sequence of attribute–value pairs separated by a delimiter.
It is also fairly common for request processors to treat a name=value pair that is missing the = sign, as if the it was name=.
E.g. if you're writing Servlet code and call servletRequest.getParameter("json"), it would return an empty string ("") for that last URL in the question.
I am currently trying to create pointers to datatype values as they cannot be linked directly. However, I would like to be able to evaluate the pointers from within the SPARQL environment, which raised specifically in the case that the desired value is part of an ordered rdf:List some questions for me. My approach is to use property paths within a SPARQL query in which I can use the defined individual, property and index of the ordered list that the pointer has attached to it.
Given the following example data with the shortened syntax for ordered lists by ttl:
ex:myObject ex:somePropery ("1" "2" "3") .
ex:myPointer ex:lookAtIndividual ex:myObject;
ex:lookAtProperty ex:someProperty ;
ex:lookAtIndex "3"^^xsd:integer .
Now I would like to create a SPARQL query that -- based on the pointer -- returns the value at the given index. To my understanding the query could/should look something like this:
SELECT ?value
WHERE {
ex:myPointer ex:lookAtIndividual ?individual ;
ex:lookAtProperty ?prop ;
ex:lookAtIndex ?index .
?individual ?prop/rdf:rest{?index-1}/rdf:first ?value .
}
But if I try to execute this query with TopBraid, it shows an error message that ?index has been found when <INTEGER> was expected. I also tried binding the index in the SPARQL query via BIND(?index-1 AS ?i), again without success. If the pointed value is not stored in a list, the query without property path works fine.
Is it in general possible to use a value that is connected via datatype property within a SPARQL query as path length for property paths?
This syntax: rdf:rest{<number>} is not standard SPARQL. So the short answer is, regrettably: no, you can't use variables as integers in SPARQL property paths, for the simple reason that you can't use integers in SPARQL property paths at all.
In an earlier draft of the SPARQL standard, there was a proposal to use this kind of syntax to allow specifying the min and max length of a property path, e.g. rdf:rest{1, 3} would match any paths using rdf:rest properties between length 1 and 3. But this was never fully standardized and most SPARQL engines don't implement it.
If you happen to use a SPARQL engine that does implement it, you will have to get in touch with the developers directly to ask if they can extend the mechanism to allow use of variables in this position (the error message suggests to me that it's currently just not possible).
As an aside: there's a SPARQL 1.2 community initiative going on. It only just got started but one of the proposals on the table is re-introducing this particular piece of functionality to the standard.
In SPARQL, I often see usage of # at the end of prefix definitions, like this:
#prefix dt: <http://example.org/datatype#>
What's the purpose? I couldn't find this in the SPARQL documentation.
Your example seems to be in Turtle, as in SPARQL the syntax would be:
PREFIX dt: <http://example.org/datatype#>
But it’s the same idea: Instead of having to use full IRIs in your query, you can use prefixed names:
In your example, the prefix label is dt. It’s mapped to the IRI http://example.org/datatype#.
In your query, it might get used as dt:foobar, where foobar is called the local part.
The mapped IRI from the prefix label and the local part get concatenated to form the "actual" IRI:
http://example.org/datatype# + foobar =
http://example.org/datatype#foobar
(Instead of using dt:foobar, you could also use <http://example.org/datatype#foobar>.)
So the # just happens to be part of the IRI design. It’s a popular way to structure vocabulary IRIs in the Semantic Web. The other popular way is using a /. See HashVsSlash.
I got a list of strings. And I want to check for every string in there. Sometimes, a string can have the suffix _anim(X) where X is an integer. If such string has that kind of suffix, I need to check for all other strings that have the same "base" (the base being the part without suffix) and finally group such strings and send them to my function.
So, given the next list:
Man_anim(1)
Woman
Man_anim(3)
Man_anim(2)
My code would discover the base Man has a special suffix, and will then generate a new list grouping all Man objects and arrange them depending on the value inside parenthesis. The code is supposed to return
Man_anim(1)
Man_anim(2)
Man_anim(3)
And send such list to my function for further processing.
My problem is, how can I check for the existence of such suffix, and afterwards, check for the value inside parenthesis?
If you know that the suffix is going to be _anim(X) every time (obviously, with X varying) then you can use a regular expression:
Regex.IsMatch(value, #"_anim\(\d+\)$")
If the suffix isn't at least moderately consistent, then you'll have to look into data structures, like Suffix Trees, which you can use to determine common structures in strings.