Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
I have a shell script that uses Wikidata Query Service (WDQS) to get required data. The SPARQL query that run WDQS takes input parameter language code.
Is there a way that I can check in shell script if the input language code is a valid Wikimedia language code as the first column data in below link
https://www.wikidata.org/wiki/Help:Wikimedia_language_codes/lists/all
These codes are possible values of wdt:P424. From the property proposal:
— Is there a big difference to ISO 639-1?
— Many of them are the same as ISO, but it is not done in a consistent way. Some language codes have two letters, some three, and a few even more. And there are also a few cases where it is completely different (als: ISO: tosk Albanian, Wikimedia: Alemannic).
You could retrieve all these codes using the following simple SPARQL query:
SELECT DISTINCT ?code { [] wdt:P424 ?code } ORDER BY ?code
Try it!
In fact, the list you have linked to is periodically generated by a bot. The full query is:
SELECT ?item ?c
(CONCAT("{","{#language:",?c,"}","}") as ?display)
(CONCAT("{","{#language:",?c,"|","en}","}") as ?displayEN)
(CONCAT("{","{#language:",?c,"|","fr}","}") as ?displayFR)
{
?item wdt:P424 ?c .
MINUS{?item wdt:P31/wdt:P279* wd:Q14827288} #--exclude Wikimedia projects
MINUS{?item wdt:P31/wdt:P279* wd:Q17442446} #--exclude Wikimedia internal stuff
}
You could:
paste the list of valid codes into your script, or
preload the list at your script startup, or
execute an ASK SPARQL query at every user input.
I would prefer the third option:
#!/bin/sh
echo "Enter language code:"
read code
request="curl -g -s https://query.wikidata.org/sparql?query=ASK{?lang%20wdt:P424%20\"$code\"}"
if $request | grep -q "true"; then
echo "Valid code";
else
echo "Invalid code";
fi
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 1 year ago.
Improve this question
I have input like below
"ID"|"Desc"
"100"|"
The data present in Desc column has new line characters.
So the data came to second line.
Some records of data went to third line. But I need all data to be present in first line."
"101"|"This record desc is correct data which has present in single line. So I need data to present in single line."
I need output like below,
"ID"|"Desc"
"100"|"The data present in Desc column has new line characters.So the data came to second line.Some records of data went to third line. But I need all data to be present in first line."
"101"|"This record desc is correct data which has present in single line. So I need data to present in single line."
Can someone please help the Perl script where we can achieve above requirement.
Use Text::CSV_XS to process the file as it can parse it correctly.
perl -MText::CSV_XS=csv -wE 'csv( in => shift,
always_quote => 1,
sep_char => "|",
eol => "\n",
on_in => sub { $_[1][1] =~ s/\n//g } );
' -- file.csv > newfile.csv
I'm testing this in a Linux shell, you might need a different eol if you're in MSWin. Also, I don't know what rules Powershell uses for quoting, co you might need to use a different type of quotes.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am extracting oracle version from windows using powershell command and i get result as 10.2.0.3.0Patch2, however i need to extract only numeric value i.e. 10.2.0.3.0 (only version number). Any way we can do it ?
Version info extracted is =
10.2.0.3.0 Production, 10.2.0.3.0Patch2 Production, 10.2.0.5.0 Production, 11.2.0.4.0 Production
You can use a regular expression to extract a substring. Example:
"10.2.0.3.0Patch2" | Select-String '((?:\d{1,3}\.){4}\d{1,3})' | ForEach-Object {
$_.Matches[0].Groups[1].Value
}
# Outputs the string '10.2.0.3.0'
You can read more about regular expressions by reading the about_Regular_Expressions help topic:
PS C:\> help about_Regular_Expressions
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a file as shown below.
2.6G kishan /home/Srikishan
10G kishan /home/data/aa
150G kishan /home/Junk
300G kishan /home/junk2
I want a command which displays only the folders which are consuming more than 50G memory. Can someone help me how I can code it using shell or Perl or TCL.
As a Perl one-liner
perl -ne'/([\d.]+)G/ and $1 > 50 and print' myfile
output
150G kishan /home/Junk
300G kishan /home/junk2
This will also ignore lines that don't contain a field like 999G
And here's the Tcl contender. It looks at every line in the file whose name is in the filename variable and prints those lines that begin with a floating-point number larger than 50.
package require fileutil
fileutil::foreachLine line $filename {if {[scan $line %f] > 50} {puts $line}}
Using awk you can do:
awk -F 'G' '$1>50' file
150G kishan /home/Junk
300G kishan /home/junk2
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to find a way to extract text in a specific and efficient way
as in this example:
'Hello Mr. Jack Andrew , your number is 894Gfsf , and your Bank ID # 734234"
I want a way to get the Name, the Number and the Bank ID Number.
I want to write software that deals with different text files and get those required values. I may not know the exact order but it must be a template like a bank statement or something.
Thanks!
It's a bit hard to understand what exactly is the problem.. If all you need to do is to split strings, here's a possible way to do it:
str = 'Hello Mr. Jack Andrew , your number is 894Gfsf , and your Bank ID # 734234';
tokenized = strsplit(str,' ');
Name = strjoin([tokenized(3:4)],' ');
Number = tokenized{9};
Account = tokenized{end};
Alternatively, for splitting you could use regexp(...,'split') or regexp(...,'tokens');
I think you want regular expressions for this. Here's an example:
str = 'Hello Mr. Jack Andrew , your number is 894Gfsf , and your Bank ID # 734234';
matches=regexp(str, 'your number is (\w+).*Bank ID # (\d+)', 'tokens');
matches{1}
ans =
'894Gfsf' '734234'
My suggestion would be to make a whole array of strings with sample patterns that you want to match, then build a set of regular expressions that collectively match all of your samples. Try each regexp in sequence until you find one that matches.
To do this, you will need to learn about regular expressions.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Input:
日本が好きです.
Output:
Nippon ga sukidesu.
Phonetical reading is unfortunately not available through Google Translate API.
KAKASI is a good, simple tool for what you want to do:
% echo "日本が好きです。" | iconv -f utf8 -t eucjp | kakasi -i euc -Ha -Ka -Ja -Ea -ka
nippongasukidesu.
% echo "日本が好きです。" | iconv -f utf8 -t eucjp | kakasi -i euc -w | kakasi -i euc -Ha -Ka -Ja -Ea -ka
nippon ga suki desu .
Or another solution is to use Yahoo! JAPAN's Japanese Language Processing API.
But it might be difficult to use because you need to sign up for Yahoo! JAPAN and register for the API key before using it and the documents are only available in Japanese.
Phonetical reading is unfortunately not available through Google Translate API.
Google translate does have that feature - Copy and paste that string into the box, and click "Read Phonetically" which is directly underneath the input text field. It will show you your exact output. It can also verbally read that string to you if you click "Listen".
http://translate.google.com/#