I want to extract items that are located within 20 km of the given latitude and longitude. Below I provide my query. The only issue that it has is related to ?lat and ?long. They have the format like this "41.3823035"^^xsd:decimal. In the ontology file, latitude and longitude have the format xsd:float.
When I run the query, I get the error:
Error 500: Infinite or NaN
Fuseki - version 2.4.1 (Build date: 2016-11-04T18:59:20+0000)
If I substitute ?lat by 41.38, and ?long by 2.22, then it works.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.test.com/my-ontology.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oo: <http://www.w3.org/2002/07/owl#>
PREFIX oa: <http://www.w3.org/ns/oa#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX lfn: <http://www.dotnetrdf.org/leviathan#>
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
SELECT DISTINCT ?id ?kwds ?lat WHERE {
?p owl:id 123 .
?p rdf:type ?service .
?service rdfs:subClassOf ?family .
?otherService rdfs:subClassOf ?family .
?item rdf:type ?otherService .
?item owl:id ?id .
?item owl:latitude ?lat .
?item owl:longitude ?long .
BIND ((lfn:degrees-to-radians(?lat)) AS ?lat1) .
BIND ((lfn:degrees-to-radians(?long)) AS ?lon1) .
BIND ((lfn:degrees-to-radians(41.384697)) AS ?lat2) .
BIND ((lfn:degrees-to-radians(2.150849)) AS ?lon2) .
BIND ((?lon2-?lon1) AS ?dlon) .
BIND ((?lat2-?lat1) AS ?dlat) .
BIND ((lfn:sq(lfn:sin(?dlat/2))+lfn:cos(?lat1)*lfn:cos(?lat2)*lfn:sin(?dlon/2) ) AS ?a) .
BIND ((2*lfn:sin-1(lfn:sqrt(?a))) AS ?c) .
BIND ((xsd:float(fn:round((6371*?c)))) AS ?dist) .
FILTER ( ?dist < 25 ) .
}
UPDATE
The problem is caused by this line BIND ((2*lfn:sin-1(lfn:sqrt(?a))) AS ?c) .. For some values of lat and lon (0.0) it returns NaN.
I solved this issue by adding IF to the BIND statement:
BIND (IF(?c != "NaN"^^xsd:double,xsd:float(fn:round((6371*?c))),999999) AS ?dist)
Related
Station_ID
ID809086
t
ID809088
ID809089
.
.
ID809098
t
ID809100
.
.
.
Basically I want to replace all 't' with previous ID +1, such as t = ID809087 and ID809099 in above scenario. Thanks in advance
Basically I want to replace all 't' with previous ID +1, such as t = ID809087 and ID809099 in above scenario. Thanks in advance
Try:
tmp = 'ID' + df['Station_ID'].str.extract(r'^ID(\d+)')[0].astype(float).interpolate().astype(int).astype(str)
df['Station_ID'] = np.where(df['Station_ID'].eq('t'), tmp, df['Station_ID'])
print(df)
Prints:
Station_ID
0 ID809086
1 ID809087
2 ID809088
3 ID809089
4 ID809098
5 ID809099
6 ID809100
I need to edit the gene names of a gff file, as shown below.
Original file:
chr1 aug gene 10708 108196 . - . ID=gene:g754;biotype=protein_coding
chr1 aug exon 10708 107528 . - . Parent=transcript:g754;Name=g754_T001.exon.1;exon_id=g754_T001.exon.1
chr1 aug gene 20588 20898 . - . ID=gene:g756;biotype=protein_coding
chr1 aug mRNA 20588 20898 . - . ID=transcript:g756;Parent=gene:g756;biotype=protein_coding;transcript_id=g756_T001
chr1 aug exon 20588 20690 . - . Parent=transcript:g756_T001;Name=g756_T001.exon.1;exon_id=g756_T001.exon.1
New file:
chr1 aug gene 10708 108196 . - . ID=gene:Gene00001;biotype=protein_coding
chr1 aug exon 10708 107528 . - . Parent=transcript:Gene00001;Name=Gene00001_T001.exon.1;exon_id=Gene00001_T001.exon.1
chr1 aug gene 20588 20898 . - . ID=gene:Gene00002;biotype=protein_coding
chr1 aug mRNA 20588 20898 . - . ID=transcript:Gene00002;Parent=gene:Gene00002;biotype=protein_coding;transcript_id=Gene00002_T001
chr1 aug exon 20588 20690 . - . Parent=transcript:Gene00002_T001;Name=Gene00002_T001.exon.1;exon_id=Gene00002_T001.exon.1
As input I have the gff file and a list with the current and new gene name keys.
g754 Gene00001
g756 Gene00002
I have written a script in python to replace the old gene names with the new gene name. The replace command works as expected, but a newline is inserted after every time the string is replaced. I don't know why this is happening and google is failing me. I did try to mimic the solution here: Renaming Name ID in gffile., but I have a separate gene name key file. I am using anaconda/python3.6
Current code:
import sys
import getopt
import operator
in_gff = open("current_gff_file.gff3", "r")
out_gff = open("new_file.gff", "w")
name_key = open("name_key_file.txt", "r")
current_name = []
new_name = []
#create 2 lists of current and new names
for name_row in name_key:
name_field = name_row.split("\t")
current_name.append(name_field[0])
new_name.append(name_field[1])
for row in in_gff:
line = row.rstrip()
if line.startswith("#"):
print(line, file = out_gff, end = "\n") #if it is a header line just print to new file
else: #loop through list of current gene names
for name in range(len(current_name)):
if current_name[name] in line:
new_line = line.replace(current_name[name], new_name[name])
print(new_line) #test loop by printing to screen, line breaks happen after every string replacement
#Output I want: ID=transcript:Gene00002;Parent=gene:Gene00002;biotype=protein_coding;transcript_id=Gene00002_T001
#Output I get: ID=transcript:Gene00002
#Parent=gene:Gene00002
#biotype=protein_coding;transcript_id=Gene00002
#_T001
else:
continue
When iterating through a file, each line still includes the trailing newline. Strip it away when building your translation table:
for name_row in name_key:
name_field = name_row.split("\t")
current_name.append(name_field[0])
new_name.append(name_field[1].strip('\n')) # store stripped names only
I think this is much easier to solve with regex.
I put your data in a file called original.txt and new_gene_names.txt and output the result to output.txt.
import re
# Note there is a lookahead and a look behind
# This expression matches any string that starts with
# `gene:` and ends with `;` and the pattern pulls out
# what is between those two things.
pattern = re.compile(r'(?<=gene:)(.*?)(?=;)')
with open('new_gene_names.txt') as gene_names,\
open('original.txt') as f,\
open('output.txt', 'w') as out_f:
# A dictionary mapping gene names to what they will be changed to
rename_dict = dict(line.split() for line in gene_names)
for line in f:
# Search for the gene name
result = pattern.search(line)
# If we found a gene name and we can rename it then we substitute it
if result and result.group(0) in rename_dict:
line = pattern.sub(rename_dict[result.group(0)], line)
out_f.write(line)
Update - to match the part in Name= as well just change the regex t:
# This expression matches any string that starts with
# `gene:` and ends with `;` OR starts with `Name=` and ends with `_`.
# and the pattern pulls out what is between the start and the end.
pattern = re.compile(r'(?<=gene:)(.*?)(?=;)|(?<=Name=)(.*?)(?=_)')
See the regex in action.
I have a RDF/Turtle Resource as below:
#prefix factory: <http://linkedfactory.iwu.fraunhofer.de/vocab#> .
#prefix : <http://linkedfactory.iwu.fraunhofer.de/data/> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix owl: <http://www.w3.org/2002/07/owl#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<http://linkedfactory.iwu.fraunhofer.de/linkedfactory> factory:contains <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/demofactory> .
<http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU> factory:contains <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/Rollex> .
<http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim> factory:contains <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab> .
<http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab> factory:contains <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/Aximus> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/BDM2000> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/Fliesspressen> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/GMX_Entgraten> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/GMX_Spanen1> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/GMX_Spanen2> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/GMX_Spanen3> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/GMX_Spanen4> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/HA100> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/Karobau> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/PRD40> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/PWZ> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/Querwalzen> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/E3-Sim/FoFab/Rollex> .
<http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab> factory:contains <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/BHKW> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/GLT> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/GMX> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/NSHV> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/NSHV-Buero> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/Rollex> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/SolarPlant> .
<http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/BHKW> factory:contains <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/BHKW/CoolingWater> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/BHKW/EmergencyCooling> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/BHKW/Generator> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/BHKW/HeatMeter> , <http://linkedfactory.iwu.fraunhofer.de/linkedfactory/IWU/FoFab/BHKW/HeatingWater> .
I transform from a natural language to a Sparql request with constituency parser for the following situations
Question : What linkedfactory contains?
PREFIX vocab: <http://linkedfactory.iwu.fraunhofer.de/vocab#>
select * where {
<http://localhost:10080/linkedfactory/demofactory> vocab:contains ?o .
}
For the following question, I need to detect "contains" verb if it is coming before the noun "linkedfactory".
Question: What contains linkedfactory? or Can you give me which one contains linkedfactory?
PREFIX vocab: <http://linkedfactory.iwu.fraunhofer.de/vocab#>
select * where {
?s vocab:contains <http://localhost:10080/linkedfactory/demofactory> .
}
How can I handle with this situation? (Note: It is used rdflib-python to create a Sparql and to parse a sentence, I use Stanford CoreNLP-Python)
Thanks in advance,
I want to build spatial index on my Jena Fuseki server.
I try to follow the doc here : https://jena.apache.org/documentation/query/spatial-query.html
But when I restart my server I have this :
[2018-05-24 17:05:03] Server INFO Apache Jena Fuseki 3.7.0
[2018-05-24 17:05:03] Config INFO FUSEKI_HOME=C:\Users\i3mainz\Desktop\JenaFusekiProject\apache-jena-fuseki-3.7.0.
[2018-05-24 17:05:03] Config INFO FUSEKI_BASE=C:\Users\i3mainz\Desktop\JenaFusekiProject\apache-jena-fuseki-3.7.0\run
[2018-05-24 17:05:03] Config INFO Shiro file: file://C:\Users\i3mainz\Desktop\JenaFusekiProject\apache-jena-fuseki-3.7.0\run\shiro.ini
[2018-05-24 17:05:04] Config INFO Configuration file: C:\Users\i3mainz\Desktop\JenaFusekiProject\apache-jena-fuseki-3.7.0\run\config.ttl
[2018-05-24 17:05:04] riot WARN [line: 32, col: 1 ] Bad IRI: Code: 4/UNWISE_CHARACTER in PATH: The character matches no grammar rules of URIs/IRIs. These characters are permitted in RDF URI References, XML system identifiers, and XML Schema anyURIs.
[2018-05-24 17:05:04] Server ERROR Exception in initialization: No rdf:type for dataset :spatial_dataset
[2018-05-24 17:05:04] WebAppContext WARN Failed startup of context o.e.j.w.WebAppContext#ca27722{/,file:///C:/Users/i3mainz/Desktop/JenaFusekiProject/apache-jena-fuseki-3.7.0/webapp/,UNAVAILABLE}
org.apache.jena.fuseki.FusekiConfigException: No rdf:type for dataset :spatial_dataset
at org.apache.jena.fuseki.build.FusekiBuilder.getDataset(FusekiBuilder.java:119)
at org.apache.jena.fuseki.build.FusekiBuilder.buildDataServiceCustom(FusekiBuilder.java:73)
at org.apache.jena.fuseki.build.FusekiBuilder.buildDataAccessPoint(FusekiBuilder.java:65)
at org.apache.jena.fuseki.build.FusekiConfig.servicesAndDatasets(FusekiConfig.java:121)
at org.apache.jena.fuseki.server.FusekiSystem.processServerConfigFile(FusekiSystem.java:266)
at org.apache.jena.fuseki.server.FusekiSystem.initServerConfiguration(FusekiSystem.java:241)
at org.apache.jena.fuseki.server.FusekiSystem.initializeDataAccessPoints(FusekiSystem.java:207)
at org.apache.jena.fuseki.server.FusekiServerListener.serverInitialization(FusekiServerListener.java:96)
at org.apache.jena.fuseki.server.FusekiServerListener.contextInitialized(FusekiServerListener.java:53)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:890)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:532)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:853)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:344)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1514)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1476)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.handler.gzip.GzipHandler.doStart(GzipHandler.java:273)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.server.Server.start(Server.java:449)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:416)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.apache.jena.fuseki.jetty.JettyFuseki.start(JettyFuseki.java:137)
at org.apache.jena.fuseki.cmd.FusekiCmd.runFuseki(FusekiCmd.java:367)
at org.apache.jena.fuseki.cmd.FusekiCmd$FusekiCmdInner.exec(FusekiCmd.java:351)
at jena.cmd.CmdMain.mainMethod(CmdMain.java:93)
at jena.cmd.CmdMain.mainRun(CmdMain.java:58)
at jena.cmd.CmdMain.mainRun(CmdMain.java:45)
at org.apache.jena.fuseki.cmd.FusekiCmd$FusekiCmdInner.innerMain(FusekiCmd.java:103)
at org.apache.jena.fuseki.cmd.FusekiCmd.main(FusekiCmd.java:67)
[2018-05-24 17:05:04] Server INFO Started 2018/05/24 17:05:04 CEST on port 3030
I really don't understand where i'm wrong.
Here my config:
# Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0
## Fuseki Server configuration file.
#prefix : <http://base/#> .
#prefix fuseki: <http://jena.apache.org/fuseki#> .
#prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
[] rdf:type fuseki:Server ;
# Example::
# Server-wide query timeout.
#
# Timeout - server-wide default: milliseconds.
# Format 1: "1000" -- 1 second timeout
# Format 2: "10000,60000" -- 10s timeout to first result,
# then 60s timeout for the rest of query.
#
# See javadoc for ARQ.queryTimeout for details.
# This can also be set on a per dataset basis in the dataset assembler.
#
# ja:context [ ja:cxtName "arq:queryTimeout" ; ja:cxtValue "30000" ] ;
# Add any custom classes you want to load.
# Must have a "public static void init()" method.
# ja:loadClass "your.code.Class" ;
# End triples.
.
<#service_spatial_tdb> rdf:type fuseki:Service ;
rdfs:label "TDB/spatial service" ;
fuseki:name "ds" ;
fuseki:serviceQuery "query" ;
fuseki:serviceQuery "sparql" ;
fuseki:serviceUpdate "update" ;
fuseki:serviceUpload "upload" ;
fuseki:serviceReadGraphStore "get" ;
fuseki:serviceReadWriteGraphStore "data" ;
fuseki:dataset :spatial_dataset ;
Can someone help me ?
I want to do something like this from the standard maps:
, ((modMask, xK_t ), withFocused $ windows . W.sink)
But the opposite ie a bit like:
, ((modMask, xK_t ), withFocused $ windows . W.doFullFloat)
I get some way with:
, ((modMask, xK_t ), withFocused $ float)
But that doesnt maximise it - it would to be
, ((modMask, xK_t ), do
withFocused $ float
[SOMETHING TO MAXIMISE WINDOW]
)
Any suggestions?
Thanks
The float function from XMonad.StackSet takes a window and a rectangle.
With import qualified XMonad.StackSet as W :
((modm, xK_f), withFocused $ windows . (flip W.float $ W.RationalRect 0 0 1 1)),
Slightly orthogonal answer but this answer does what I actually want - just not how I had planned to it: Using MultiToggle
This is the magic module: MultiToggle
And I did it by modifying my layouts to inject
id . smartBorders . mkToggle (NOBORDERS ?? FULL ?? EOT)
before the list of layouts and then added a keymap
, ((modMask, xK_w ), sendMessage $ LMT.Toggle FULL)
If anyone can give an answer to my original question/method, I'll vote it as the correct answer! Thanks.
Another alternative seems to be provided Layout.Maximise