My query starts like this:
SELECT
#MIN(?dateYear) AS ?dateYears)
(GROUP_CONCAT(DISTINCT ?dateYear ; separator = ", ") AS ?dateYears)
(CONCAT(GROUP_CONCAT(DISTINCT ?gameENLabel; separator = ", ") ,", ", GROUP_CONCAT(DISTINCT ?gameJALabel; separator = ", "), ", ", GROUP_CONCAT(DISTINCT ?hepburnLabel; separator = ", "), ", ", GROUP_CONCAT(DISTINCT ?gameZHLabel; separator = ", "), ", ", GROUP_CONCAT(DISTINCT ?pinyinLabel; separator = ", ")) as ?wookie)
(GROUP_CONCAT(DISTINCT ?dataLink ; separator = ", ") AS ?dataLinks)
#(?game AS ?dataPages)
(GROUP_CONCAT(DISTINCT ?wikiLink ; separator = ", ") AS ?wikiLinks)
(GROUP_CONCAT(DISTINCT ?wikiName ; separator = ", ") AS ?wikiNames)
WHERE {
...
}
It works, but when GROUP_CONCAT(DISTINCT ?gameJALabel; separator = ", ") returns an empty spring, the comma immediately following it is still rendered. Can the CONCAT command be supplied with a separator that only gets rendered if the preceding command returns something? Is there a better way to do all this that I don't know about? Thanks!
Related
I have a question I wrote this script to format an arabic text to a certain format. But I found a problem then when I type a longer sentence it adds more dots then there are letters. I will paste the code here and explain what the problem is.
import itertools
while True:
input_cloze_deletion = input("\nEnter: text pr 'exit'\n> ")
input_exit_check = input_cloze_deletion.strip().lower()
if input_exit_check == "exit":
break
# copy paste
interpunction_list = ["الله", ",", ".", ":", "?", "!", "'"]
# copy paste
interpunction_list = [ ",", ".", ":", "?", "!", "'", "-", "(", ")", "/", "الله", "اللّٰـه"]
text_replace_0 = input_cloze_deletion.replace(",", " ,")
text_replace_1 = text_replace_0.replace(".", " .")
text_replace_2 = text_replace_1.replace(":", " :")
text_replace_3 = text_replace_2.replace(";", " ;")
text_replace_4 = text_replace_3.replace("?", " ?")
text_replace_5 = text_replace_4.replace("!", " !")
text_replace_6 = text_replace_5.replace("'", " ' ")
text_replace_7 = text_replace_6.replace("-", " - ")
text_replace_8 = text_replace_7.replace("(", " ( ")
text_replace_9 = text_replace_8.replace(")", " ) ")
text_replace_10 = text_replace_9.replace("/", " / ")
text_replace_11 = text_replace_10.replace("الله", "اللّٰـه")
text_split_list = text_replace_11.split()
count_number = []
letter_count_list = []
index_list = itertools.cycle(range(1, 4))
for letter_count in text_split_list:
if letter_count in interpunction_list:
letter_count_list.append(letter_count)
elif "ـ" in letter_count:
letter_count = len(letter_count) - 1
count_number.append(letter_count)
print(letter_count)
else:
letter_count = len(letter_count)
count_number.append(letter_count)
print(letter_count)
for count in count_number:
letter_count_list.append(letter_count * ".")
zip_list = zip(text_split_list, letter_count_list)
zip_list_result = list(zip_list)
for word, count in zip_list_result:
if ((len(word)) == 2 or word == "a" or word == "و") and not word in interpunction_list :
print(f" {{{{c{(next(index_list))}::{word}::{count}}}}}", end="")
elif word and count in interpunction_list:
print(word, end = "")
else:
print(f" {{{{c{(next(index_list))}::{word}::{count}}}}}", end="")
when I type كتب عليـ ـنا و علـ ـي
the return is {{c1::كتب::...}} {{c2::عليـ::...}} {{c3::ـنا::...}} {{c1::و::..}} {{c2::علـ::..}} {{c3::ـي::..}}
but it should be
{{c1::كتب::...}} {{c2::عليـ::...}} {{c3::ـنا::..}} {{c1::و::.}} {{c2::علـ::..}} {{c3::ـي::.}}
I add a print function the print the len() results and the result is correct but it add an extra dot in some case.
But when I type just a single "و" it does a correct len() function but when I input a whole sentence it add an extra dot and I don't know why.
please help
I am trying to do something like this:
query = (
"select mandant,posnr,"
"lieferbedingung,nrkreis_nr"
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
"and mandant <> 999;"
)
queryset += [(query, filename)]
df = pd.read_sql(query, engine.connect())
but I get this error:
SQLNumResultCols failed: [IBM][CLI Driver][IDS/UNIX64] A syntax error has occurred. SQLCODE=-201
I guess its becuase of the quotation marks but i'm not sure how to modify it.
I already tried without backslash too
[SQL: select mandant,posnr,systemdat,fk_kto_auf,fk_kto_not1,fk_kto_not2,fk_kto_empf,fk_kto_adr5,fk_kto_adr6,fk_kto_adr7,fk_kto_adr8,fk_kto_adr9,adr_auftraggeber,anzahl_kolli,volumen,gewicht,lieferbedingung,aufdat,ankdat,versandort,modus,ladehafen,loeschhafen,bereich,nrkreis_nr from eakopf_t where posnr[10,10] = " " , and posnr[1,2] not in ("99","RE","UB") and mandant <> 999;]
You have:
query = (
"select mandant,posnr,"
"lieferbedingung,nrkreis_nr"
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
"and mandant <> 999;"
)
There is no space separating nrkreis_nr from from, so the printed query would contain:
select mandant,posnr,lieferbedingung,nrkreis_nrfrom eakopf_t where …
It's probably best to put spaces at the start (or the end) of each continuation line:
query = (
"select mandant, posnr,"
" lieferbedingung, nrkreis_nr"
" from eakopf_t where posnr[10,10] = \" \" and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
" and mandant <> 999;"
)
It's not necessary when there is a punctuation character at the end of one line or the beginning of the next (so the comma at the end of the first line of the string means the space at the start of the next line is not mandatory), but it is safest.
I also removed a stray comma and space in:
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
The SPARQL query below throws errors. What's wrong? Protege syay that there's a lexical error at line 1, column 8, Encountered " " (32), after : "private"
private static ResultSet getСontNameFirst(OntModel model, string nameWord) {
String queryString = String.format(
"PREFIX wordnet:<http://www.owl-ontologies.com/wordnet.owl#> " +
"SELECT ?word " +
"WHERE { " +
" ?%s wordnet:?pre ?subject " +
" { SELECT DISTINCT ?pre WHERE { " +
" ?word wordnet:?pre ?otherword " + "
} }" +
" OPTIONAL { ?%s wordnet:?pre ?word}" +
"}", nameWord);
QueryExecution qe = QueryExecutionFactory.create(query);
ResultSet results = qe.execSelect();
return results;
}
I would like to clean a column Header of the table so that my column header that has a name like below:
[Space][Space][Space]First Name[Space][Space]
[Space]MaintActType[Space]
TECO date[Space]
FIN Date
ABC indicator
COGS
Created On
And my desired Column Header Name to be like below:
First Name
Main Act Type
TECO Date
FIN Date
ABC Indicator
COGS
Created On
my code is as below:
let
Source = Excel.Workbook(File.Contents("C:\RawData\sample.xlsx"), null, true),
#"sample_Sheet" = Source{[Item="sample",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"sample_Sheet", [PromoteAllScalars=true]),
#"Trim ColumnSpace" = Table.TransformColumnNames(#"Promoted Headers", Text.Trim),
#"Split CapitalLetter" = Table.TransformColumnNames(#"Trim ColumnSpace", each Text.Combine(Splitter.SplitTextByPositions(Text.PositionOfAny(_, {"A".."Z"},2)) (_), " ")),
#"Remove DoubleSpace" = Table.TransformColumnNames(#"Split CapitalLetter", each Replacer.ReplaceText(_, " ", " ")),
#"Capitalise FirstLetter" = Table.TransformColumnNames(#"Remove DoubleSpace", Text.Proper),
#"Remove Space" = Table.TransformColumnNames(#"Capitalise FirstLetter", each Text.Remove(_, {" "})),
#"Separate ColumnName" = Table.TransformColumnNames(#"Remove Space", each Text.Combine(Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}) (_), " "))
in
#"Separate ColumnName"
However, i get the result as below. Which is not what i wanted as all the capital letter we combined together. How do i change the code so that i get the result as wanted? I would really appreciate your help, please.
First Name
Main Act Type
TECODate
FINDate
ABCIndicator
COGS
Created On
Alternatively, i changed the code to:
let
Source = Excel.Workbook(File.Contents("C:\RawData\sample.xlsx"), null, true),
#"sample_Sheet" = Source{[Item="sample",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"sample_Sheet", [PromoteAllScalars=true]),
#"Trim ColumnSpace" = Table.TransformColumnNames(Input, Text.Trim),
#"Separate ColumnName" = Table.TransformColumnNames(#"Trim ColumnSpace", each Text.Combine(Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}) (_), " ")),
#"Capitalise FirstLetter" = Table.TransformColumnNames(#"Separate ColumnName", Text.Proper)
in
#"Capitalise FirstLetter"
Unfortunately it return the result like so:
First Name
Main Act Type
Teco Date
Fin Date
Abc Indicator
COGS
Created On
I have no idea how to play around the code anymore.
One way is to mark the existing spaces with something (I used "ZZZ") and restore them back to spaces at the end. Here's your code with a couple of tweaks. Thanks for your code. I was trying to do Text.Proper and your sample helped me!
let
Source = Input,
#"Replaced Value" = Table.ReplaceValue(Source,"[Space]"," ",Replacer.ReplaceText,{"Headers"}),
#"Transposed Table" = Table.Transpose(#"Replaced Value"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Trim ColumnSpace" = Table.TransformColumnNames(#"Promoted Headers", Text.Trim),
#"Change space to ZZZ" = Table.TransformColumnNames(#"Trim ColumnSpace", each Replacer.ReplaceText(_, " ", " ZZZ ")),
#"Split CapitalLetter" = Table.TransformColumnNames(#"Change space to ZZZ", each Text.Combine(Splitter.SplitTextByPositions(Text.PositionOfAny(_, {"A".."Z"},2)) (_), " ")),
#"Capitalise FirstLetter" = Table.TransformColumnNames(#"Split CapitalLetter", Text.Proper),
#"Remove Space" = Table.TransformColumnNames(#"Capitalise FirstLetter", each Text.Remove(_, {" "})),
#"Separate ColumnName" = Table.TransformColumnNames(#"Remove Space", each Text.Combine(Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}) (_), " ")),
#"Change ZZZ to space" = Table.TransformColumnNames(#"Separate ColumnName", each Replacer.ReplaceText(_, "ZZZ", " ")),
#"Remove DoubleSpace" = Table.TransformColumnNames(#"Change ZZZ to space", each Replacer.ReplaceText(_, " ", " "))
in
#"Remove DoubleSpace"
Heres specifically the sql text in a file.
select substr(to_char(ctl.tody_run_dt,'YYYYMMDD'),1,8) tody_yyyymmdd,
substr(to_char(cdr.nxt_proc_dt,'YYYYMMDD'),1,8) nxt_proc_yyyymmdd,
add_months(ctl.tody_run_dt - cdr.past_accru_dys,
- ct.nbr_cycl_for_adj) beg_proc_dt,
from tbl_crd )
and prv.calendar_run_dt =
( select max(calendar_run_dt)
from run_tbl1 prv2
From this i wish to extract all the tables,
This seems pretty complicated to be done through a regexp? Is there a way? Or should i write a program? I just cant come up with an algorithm.
You might be able to do something like a linear search like this. It relaxed for your example
and just targets the from keyword, excludes other keywords.
The table data is captured in group 1. It has to be split appart upon each
match through the find loop.
# from\s+((?!(?:select|from|where|and)\b)\w+(?:[,\s]+(?!(?:select|from|where|and)\b)\w+)*)
from
\s+
( # (1 start), Contains all the table info
(?! # exclude keywords
(?:
select
| from
| where
| and
)
\b
)
\w+
(?:
[,\s]+
(?! # exclude keywords
(?:
select
| from
| where
| and
)
\b
)
\w+
)*
) # (1 end)
Perl test case
$/ = undef;
$str = <DATA>;
while ( $str =~ /from\s+((?!(?:select|from|where|and)\b)\w+(?:[,\s]+(?!(?:select|from|where|and)\b)\w+)*)/g )
{
print "\n'$1'";
}
__DATA__
select substr(to_char(ctl.tody_run_dt,'YYYYMMDD'),1,8) tody_yyyymmdd,
substr(to_char(cdr.nxt_proc_dt,'YYYYMMDD'),1,8) nxt_proc_yyyymmdd,
add_months(ctl.tody_run_dt - cdr.past_accru_dys,
- ct.nbr_cycl_for_adj) beg_proc_dt,
(ctl.tody_run_dt + cdr.futr_accru_dys) end_proc_dt,
ctl.tody_end_proc_dt,
ctl.prv_end_proc_dt,
cdr.fst_proc_dy,
cdr.lst_proc_dy,
cdr.accru_nbr_of_dys,
cdr.dy_of_wk,
from run_tbl1 cdr, runtbl
run_tbl1 prv,
run_tbl_cntl ctl,
tbl_crd ct
where cdr.calendar_run_dt = ctl.tody_run_dt
and ct.nbr_cycl_for_adj =
( select max(nbr_cycl_for_adj)
from tbl_crd )
and prv.calendar_run_dt =
( select max(calendar_run_dt)
from run_tbl1 prv2
where prv2.calendar_run_dt < ctl.tody_run_dt
and prv2.accru_nbr_of_dys = 1 )
and rownum = 1
Output >>
'run_tbl1 cdr, runtbl
run_tbl1 prv,
run_tbl_cntl ctl,
tbl_crd ct'
'tbl_crd'
'run_tbl1 prv2'
First I had to correct some syntax errors within your SQL.
... cdr.dy_of_wk, <<<< the comma is wrong
from run_tbl1 cdr ...
Here the proove of concept using JSQLParser V0.8.9 (https://github.com/JSQLParser/JSqlParser) to extract tablenames.
public static void main(String[] args) throws JSQLParserException {
TablesNamesFinder tfinder = new TablesNamesFinder();
String sql = "select substr(to_char(ctl.tody_run_dt,'YYYYMMDD'),1,8) tody_yyyymmdd, "
+ " substr(to_char(cdr.nxt_proc_dt,'YYYYMMDD'),1,8) nxt_proc_yyyymmdd, "
+ " add_months(ctl.tody_run_dt - cdr.past_accru_dys, "
+ " - ct.nbr_cycl_for_adj) beg_proc_dt, "
+ " (ctl.tody_run_dt + cdr.futr_accru_dys) end_proc_dt, "
+ " ctl.tody_end_proc_dt, "
+ " ctl.prv_end_proc_dt, "
+ " cdr.fst_proc_dy, "
+ " cdr.lst_proc_dy, "
+ " cdr.accru_nbr_of_dys, "
+ " cdr.dy_of_wk "
+ " from run_tbl1 cdr, runtbl, "
+ " run_tbl1 prv, "
+ " run_tbl_cntl ctl, "
+ " tbl_crd ct "
+ " where cdr.calendar_run_dt = ctl.tody_run_dt "
+ " and ct.nbr_cycl_for_adj = "
+ " ( select max(nbr_cycl_for_adj) "
+ " from tbl_crd ) "
+ " and prv.calendar_run_dt = "
+ " ( select max(calendar_run_dt) "
+ " from run_tbl1 prv2 "
+ " where prv2.calendar_run_dt < ctl.tody_run_dt "
+ " and prv2.accru_nbr_of_dys = 1 ) "
+ " and rownum = 1 ";
//parse SQL statement
Select select = (Select) CCJSqlParserUtil.parse(sql);
//extract table names
List<String> tableList = tfinder.getTableList(select);
System.out.println(tableList);
}
and it outputs
[run_tbl1, runtbl, run_tbl_cntl, tbl_crd]