Use of namespace prefixes in import statements for Turtle documents causes failures when using OWLAPI - owl-api

If an ontology being saved (using OWLAPI) in Turtle format uses a set of prefixes, the import statements for the imported ontologies, use the declared prefixes. The ontology thus saved using the prefixes cannot be read back by the OWLAPI Turtle parser. The import statement is flagged as source of the problem.
Lets say Onto2 imports Onto1 and Onto3 (see below for declarations). Saving Onto2 results in following:
#prefix : <http://example.com/ontology/Onto2#> .
#prefix OT1: <http://example.com/ontology/Onto1> .
#prefix OT2: <http://example.com/ontology/Onto2> .
#prefix OT3: <http://example.com/ontology/Onto3> .
<http://example.com/ontology/Onto2> rdf:type owl:Ontology ;
owl:imports OT1:# ,
OT3:# .
When Onto2 is read back by the OWLAPI Turtle parser, it complains
org.openrdf.rio.RDFParseException: Expected '.', found 'O' [line 13]
The import statement is on line 13.

From the Turtle language specs, I think the problem is the hash character. It is not allowed in that position, where it will be interpreted as the start of a comment. See here for details.

Related

Retaining Header name while importing flat file into sql

I am trying to import a flat file into sql. My headers look like this in notepad
SCSItem.[Item],SCSItem.[PhaseOutItemType]
But when I import this into sql using "Import Data" it removes the period and the bracket. This is what it looks like after the import
Is there a way to retain the header info ?
Both periods . and square brackets [] are reserved syntax in SQL Server. If you want the field name to be:
SCSItem.[Item]
Then you need to use the other, ANSI Standard, identifier quote, which is ".
For example:
CREATE TABLE has_brackets
("SCSItem.[Item]" nvarchar(100)
,"SCSItem.[PhaseOutItemType]" nvarchar(100)
);

Exporting data files using loop in Stata

I have a large dataset of 20 cities and I'd like to split it into smaller ones for each city. Each variable in the dataset will be exported into a text file.
foreach i in Denver Blacksburg {
use "D:\Data\All\AggregatedCount.dta", clear
drop if MetroArea != `i'
export delimited lnbike using "D:\Data/`"`i'"'/DV/lnbike.txt", delimiter(tab) replace
export delimited lnped using "D:\Data/`"`i'"'/DV/lnped.txt", delimiter(tab) replace
}
I tried i' and"`i'"' in the export commands but none of them worked. The error is
"Denver not found."
I also have cities that have space in between, such as Los Angeles. I tried
local city `" "Blacksburg" "Los Angeles" "Denver" "'
foreach i of city {
use "D:\Data\All\AggregatedCount.dta", clear
drop if MetroArea != `i'
export delimited lnbike using "D:/Data/`"`i'"'/DV/lnbike.txt", delimiter(tab) replace
export delimited lnped using "D:/Data/`"`i'"'/DV/lnped.txt", delimiter(tab) replace
}
This didn't work either. Do you have any suggestion?
If you want to continue with Stata, the only thing you would need to change in your first code snippet is
`"`i'"'
to
\`i'
Note the \ so that your code looks like:
export delimited lnbike using "D:\Data\\`i'/DV/lnbike.txt", delimiter(tab) replace
(I would personally change all of the forward slashes (/) to back slashes (\) in general anyway) but the extra one is because a backslash before a left single quote in a string evaluates to just the left single quote. Having the second backslash tells Stata that you want the local macro i to be evaluated.
Your second code snippet could work if you also changed
foreach i of city {
to
foreach i of `city' {
It might be helpful to read up on local macros: they can definitely be confusing, but are powerful if you know how to use them.
This answer overlaps with the helpful answer by #Eric HB.
Given 20 (or more) cities you should not want to type those city names, which is tedious and error-prone, and not needed. Nor do you need to read in the dataset again and again, because you can just export the part you want. This should get you closer.
use "D:/Data/All/AggregatedCount.dta", clear
* result is integers 1 up, with names as value labels
egen which = group(MetroArea), label
* how many cities: r(max), the maximum, is the number
su which, meanonly
forval i = 1/`r(max)' {
* look up city name for informative filename
local where : label (which) `i'
export delimited lnbike if which == `i' using "D:/Data/`where'/DV/lnbike.txt", delimiter(tab) replace
export delimited lnped if which == `i' using "D:/Data/`where'/DV/lnped.txt", delimiter(tab) replace
}
The principles concerned not yet discussed:
-- When testing for literal strings, you need " " or compound double quotes to delimit such strings. Otherwise Stata thinks you mean a variable or scalar name. This was your first bug, as given
drop if MetroArea != `i'
interpreted as
drop if MetroArea != Denver
Stata can't find a variable Denver. As you found, you need
drop if MetroArea != "`i'"
-- Windows uses the backslash as a separator in file and directory names, but Stata also uses the backslash as an escape character. If you use local macro names after such file separators, the result can be quite wrong. This is documented at [U] 18.3.11 in this manual chapter and also in this note. Forward slashes are never a problem, and Stata understands them as you intend, even with Windows.
All that said, it is difficult to believe that you will be better off with lots of little files, but that depends on what you want to do with them.

Create Assembly is successful, nothing found in sys.assembly_modules

First attempt at a CLR Integration, so I can use Regex tools.
I create the assembly:
CREATE ASSEMBLY SQLRegexTools
FROM 'D:\CODE\SQLRegexTools\SQLRegexTools\bin\Release\SQLRegexTools.dll'
This succeeds, and the assembly appears in SELECT # FROM sys.assemblies.
But there are no records returned to SELECT * FROM sys.Assembly_modules.
And when I try to CREATE FUNCTION to call one of the methods,
CREATE FUNCTION RegExMatch(#pattern varchar(max)
, #SearchIn varchar(max)
, #options int)
RETURNS varchar
EXTERNAL NAME SQLRegexTools.Functions.RegExMatch
I get an error 'Msg 6505, Could not find Type "Functions" in assembly 'SQLRegexTools.'
The class name of the VB module is "Functions". Why is this called a type in the error, and why might I not be seeing anything in the modules?
This error occurs when SQL Server is unable to resolve the name as provided. Try the snippet below to see if this resolves the issue.
CREATE FUNCTION RegExMatch(#pattern varchar(max)
, #SearchIn varchar(max)
, #options int)
RETURNS varchar
AS EXTERNAL NAME SQLRegexTools.[Functions].RegExMatch
The resolution of individual functions/methods for accessing native code is relatively indistinguishable from a multipart object name (e.g. a type).
An additional note is that native code that utilizing nested namespaces must fully qualify nested namespaces within the same pair of quotes. For example, if RegExMatch were located at SQLRegexTools.A.B.C.RegExMatch, you would reference this as SQLRegexTools.[A.B.C].RegExMatch when using it with EXTERNAL NAME in SQL Server.
That hits the answer Joey. Thank you.
There are several gotchas in this process I learned after much sleuthing and testing. They are often buried in long posts about the entire process, I will summarize here:
As Joey explained, the fully qualified name is needed. To be more complete...
Example:
1 2 3 4
[SQLRegexToolsASM].[SQLRegexToolsNS.RegexFunctionsClass].RegExMatch
This is the assembly name in the CREATE ASSEMBLY step.
This is the Root Namespace from the properties of the assembly project. If you declared a namespace or two, they must be included in their proper order, after this item and before item 3 in this list. Observe all these namespaces are enclosed in their own square brackets.
assembly.[rootnamespace.namespace.namespace].classname.methodnameā€
This is the Class Name you assigned to the class, maybe like this
Public Class RegexFunctionsClass
The name of the method defined in your VB or C# assembly.

How to use special characters in SQL Server variables?

I'm trying to declare a variable like #wi-fi in SQL Server but dash character in not allowed. There are other characters like / * - ( ) with same problem. I know for table or column name we can put it in the [] but what about declaring variables? is there a solution?
I have already searched the web but couldn't find any way.
Local variable names must comply with the rules for identifiers. MSDN says that :
When identifiers are used in Transact-SQL statements, the identifiers that do not comply with these rules must be delimited by double quotation marks or brackets.
But this rule is not valid for variables naming. In SQL Server there is a restriction on variable names. All variable names must begin with a single # sign. After that the variable name must follow the rules for identifiers and can contain a total of 128 characters.When we say characters, we mean that the name can contain letters, numbers, the # sign, the pound sign, the dollar sign and the underscore character. The variable name can not contain any dash or spaces.
READ MORE HERE
Some context to answer people such as #Alex who need to know the "why" for questions like this:
I ran into a similar problem, I needed to use just a small piece of a URL saved in my db where the front and ends were irrelevant.
I first attempted to use:
declare #variable varchar(250) = %x%;
SELECT * FROM tblone WHERE column1 LIKE '#variable'
however this returned error: Arithmetic overflow error converting numeric to data type varchar
My working query was formatted:
declare #variable varchar(1000) = x;
SELECT * FROM tblone WHERE column1 LIKE '%'+#variable+'%'

using mongo-c-driver can not use regular expressions containing forward slash (/)

I am trying to use the C-API for MongoDB. I want to find records with a name matching a regular expression containing slashes (/). If I run the mongo command line I get 40 results for the query:
db.test_006.find({'name':/^\/TEST::TOP:NEWSTAT\/_data_[0-9]*/})
which is correct. When I try to code this in C I can not get it to match.
using:
bson_append_regex( &query, "name","/TEST::TOP:NEWSTAT/" , "" )
I find all the records and more.
All combinations of \\/ or even [/] or [\\/] do not find any records. I also tried \\x2F.
Is this just broken ? Am I missing something ? There is plenty of information about compiling regular expressions to use with other languages (python, java, etc...)
Thanks,
-Josh

Resources