How do I handle SPARQL duplicate specific values? - duplicates

SELECT ?s ?data ?pro ?o
WHERE {
?s rdf:type rdfs:Class .
?data rdf:type ?s .
pro rdf:type rdf:Property .
?data ?pro ?o .}
This SPARQL result is as follows:
?s ?data ?pro ?o
A1 B1 A1.a 0
A1 B1 A1.b 0
A1 B1 A1.c 1
A1 B1 A1.d 1
A2 B2 A2.a 0
A2 B2 A2.b 0
.
.
.
The result I want is
A1 B1 A1.a 0
A1.b 0
A1.c 1
A1.d 1
A2 B2 A2.a 0
A2.b 0
.
.
.
Is this possible?
I understand that DISTINCT is not the solution I want.
Thank you. Happy New Year

Related

Generate Permutations using Hunspell affix rules

The bounty expires in 2 days. Answers to this question are eligible for a +50 reputation bounty.
shantanuo wants to draw more attention to this question.
let's assure there is a new language where a combination of 3 letters in any order are valid. For e.g. abc, acb, bac, bca, cba, bab all are valid. How do I write a hunspell affix file for this?
affix file:
PFX A Y 1
PFX A 0 a .
PFX B Y 1
PFX B 0 b .
PFX C Y 1
PFX C 0 c .
SFX a Y 1
SFX a 0 a .
SFX b Y 1
SFX b 0 b .
SFX c Y 1
SFX c 0 c .
This is just an example assuming there are only 3 characters (ABC) but it can be extended to A to Z.
Dict file:
a/BCbc
b/ACac
c/ABab
Is there any other better way to write this code or this is the only way to achieve this?

How to filter rows instead of columns in Google Sheets?

I have a shared google sheet at work that would look like what is down below. I want to filter out all the rows that have 0's in all 3 columns. I've tried a =filter function, but the problem with it is that it only does 1 row/column at a time. Any ideas?
value 1 value 2 value 3
8485 2515 0
121 0 0
36 0 415
0 0 0
0 0 0
0 1551 0
try:
=QUERY({A:C, TRANSPOSE(QUERY(TRANSPOSE(A:C),,9^9))},
"select Col1,Col2,Col3 where Col4 <> '0 0 0'")
Solution:
If you want to do that using Google Apps Script, then:
function myFunction() {
const sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
const data = sheet1.getRange('A1:C'+sheet1.getLastRow()).getValues();
const fdata = data.filter(r=>r[0]!=0 || r[1]!=0 || r[2]!=0);
sheet1.getRange(1,5,fdata.length,fdata[0].length).setValues(fdata);
}
Input of my sheet and output:
Here are a few simple solutions:
=QUERY(
A:C;
"WHERE A IS NOT NULL
AND A * A + B * B + C * C <> 0"
)
=QUERY(
A:C;
"WHERE A IS NOT NULL
AND (A <> 0 OR B <> 0 OR C <> 0)"
)
[Solved]:
You can try this solution:
In new column (as example [Column D]) add a Concatenate formula like this:
=A1&B1&C1
Applicate to All Rows from row D1 to D7.
Then you just Add a Filter to this column: [Column D] Unselect this Value "000" with three zeros.

Create a function determine_grade

how can I create a function that determines_grade which accepts the grade between 0-100 and returns the letter grade based on the following scale?
. 90-100 A
. 80-89 B
. 70-79 C
. 60-69 D
. below 60 F
and call my function with each of the following argument
function call score
1 90
2 85
3 73
4 62
5 58
In Python, you can use the if/elif/else logic in your function, and since this logic evaluates from the "top-down", after checking if the input is valid, only a single criteria has to be checked at each step. For example:
def determine_grade(score):
if score < 0 or score > 100:
return "Score not between 0-100"
elif score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"

Symfony combinate 2 queries

I would like to get max date from other query insert to current query. Look at my codes pls.
Data:
inv_id inv_date inv_export inv_code
1 2016-03-14 0 a2
2 2016-03-13 0 a1
3 2016-04-13 1 a1
4 2016-03-14 0 a1
Result:
for inv_export = 0 return a2 & a1
for inv_export = 1 return a1
mysql (working fine):
SELECT ..., i.inv_date, i.inv_export
FROM Sp.inventory AS i
...
WHERE i.inv_date IN (
SELECT max(i.inv_date) from Sp.inventory WHERE i.inv_export = 1
);
I have tried convert it to symfony:
$qb = $this
->createQueryBuilder('i')
->select('..., i.invDate')
...
->where('i.invExport = :export AND i.invDate = MAX(i.invDate)')
->setParameter('export', $export);
You can use a subquery as follow:
$sub = $this->createQueryBuilder('i2');
$sub->select("max(i2.inv_date)");
$sub->where("i.invExport= i2.invExport");
$qb = $this
->createQueryBuilder('i')
->select('..., i.invDate')
...
->where('i.invDate = ( '.$sub->getDQL().' )');
->andWhere('i.invExport = :export')
->setParameter('export', $export);
hope this help

Boolean Expression for 4 input Logic gates

I have 4 inputs; (A, B, C, D) and 3 outputs; (X,Y,Z).
1)X is true when the input is less than 0111.
2)Y is true when the input is greater than 0111.
3)Z is true when the input is 0111.
Can someone help me out with the Boolean Expression for X?
I have already obtained the expressions for Y and Z which are as follows:
Y = A
_
Z = A . (B . C . D)
X is true when neither Y or Z are true:
_ _
X = Y + Z
or
_____
X = Y . Z
The expansion of which can be simplified, hint:
_ _ _
A + A = A
From first principles, any expression can be obtained from the truth table by OR'ing the true AND expression for each row that has a true result (then simplifying where possible); for example:
A B C X
--------- _ _ _
0 0 0 1 = A . B . C
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 1 = A . B . C
_ _ _
X = (A . B . C) + (A . B . C)
alternatively:
_________
X = (A + B + C) + (A . B . C)
For large truth tables, this can become cumbersome (which is why my example has only three variables), in these cases a Karnaugh Map could be used instead.