in microbit how to make variable save? - variables

i want make reading variable led in a button and b.
and button c(a+b) show variable led.
if i push the button a b b a than show the led a b b a
but can only show when i push the last button
so help me
how to make?
(Button.AB, function () {
showImage(0)
})
(Button.A, function () {
images.createImage(
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
)
})
input.onButtonPressed(Button.B, function () {
mos = images.createImage(
. . . . .
. . . . .
# # # # #
. . . . .
. . . . .
)
})
let mos: Image = null
images.createImage(
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
)
there just read only push last button

Related

Child element doesn't except property value

I have a property defined inside QML i.e. txt_margin and txt_size to be passed on to child element (i.e. Text) but the child item doesn't update with this new value.
Here is portion of my code
Row {
. . .
readonly property int txt_margin: 4
readonly property int txt_size: 15
. . .
Rectangle {
. . .
. . .
. . .
Text {
. . .
. . .
font.pixelSize: txt_size // This doesn't work
anchors.leftMargin: txt_margin // This doesn't work
}
}
}

How to determine if one range contains another?

Consider the following example:
:rangeA :lowerLimit :LeftMarginA ;
:upperLimit :RightMarginA .
:rangeB :lowerLimit :LeftMarginB ;
:upperLimit :RightMarginB .
:LeftMarginA :hasValue 20 ;
:RightMarginA :hasValue 80 .
:LeftMarginB :hasValue 30 ;
:RightMarginB :hasValue 60 .
How to get inference results using SPARQL or SWRL
:rangeA :Contains :rangeB
My idea is:
if (:LeftMarginB >= :LeftMarginA)
&& (:RightMarginB <= :RightMarginA)
then :rangeA :contains :rangeB
But how do I write this SPARQL or SWRL statement?
Thanks for help.
If you can write a SELECT query that selects one range that contains another, it's just one more step to convert it into a CONSTRUCT WHERE query that generates the triple that captures your inference. For instance:
Some Data
#prefix : <urn:ex:>
:x :lower 30 ; :upper 60 .
:y :lower 20 ; :upper 80 .
A query
prefix : <urn:ex:>
construct {
?a :contains ?b
} where {
?a :lower ?la ; :upper ?ua .
?b :lower ?lb ; :upper ?ub .
filter ( ?lb < ?la && ?ua < ?ub )
}
The result
#prefix : <urn:ex:> .
:x :contains :y .
I've tested and this does work:
prefix : <#>
CONSTRUCT { ?rangeA :contains ?rangeB . }
WHERE {
{
SELECT ?rangeA ?rangeB
WHERE {
?rangeA :lowerLimit ?LeftMarginA ;
:upperLimit ?RightMarginA .
?rangeB :lowerLimit ?LeftMarginB ;
:upperLimit ?RightMarginB .
?LeftMarginA :hasValue ?valueLA.
?RightMarginA :hasValue ?valueRA.
?LeftMarginB :hasValue ?valueLB.
?RightMarginB :hasValue ?valueRB.
Filter ((?valueLB >= ?valueLA) && (?valueRB <= ?valueRA)
&& (?rangeA !=?rangeB)) ​
}
}
}
But that doesn't take into account the inclusion of the boundary.
If consider boundary inclusion like :
:LeftMarginA :hasValue 20 ;
:inclusive True.
:RightMarginA :hasValue 80 ;
:inclusive False.
How can SPARQL statements be modified to work properly?
Thank you all, the final solution is as follows:
#-----rdf data
#prefix : <#> .
:rangeA :lowerLimit 20 ;
:lowerLimitInclusiveA false ;
:upperLimit 80 ;
:upperLimitInclusiveA false .
:rangeB :lowerLimit 20.5 ;
:lowerLimitInclusiveB false ;
:upperLimit 60 ;
:upperLimitInclusiveB false .
#---sparql query ========================
prefix : <#>
CONSTRUCT { ?rangeA :contains ?rangeB . }
WHERE {
{
SELECT ?rangeA ?rangeB
WHERE {
?rangeA :lowerLimit ?LeftMarginA ;
:lowerLimitInclusiveA ?lowerA ;
:upperLimit ?RightMarginA ;
:upperLimitInclusiveA ?upperA .
?rangeB :lowerLimit ?LeftMarginB ;
:lowerLimitInclusiveB ?lowerB ;
:upperLimit ?RightMarginB ;
:upperLimitInclusiveB ?upperB .
Filter (if(?lowerA,?LeftMarginB>=?LeftMarginA, ?LeftMarginB>?LeftMarginA)
&& if(?upperA, ?RightMarginB<=?RightMarginA, ?RightMarginB<?RightMarginA)
&& (?rangeA!= ?rangeB))
}
}
}

Sparql query to get only top-most elements matching criteria

I have multiple trees where nodes are linked with hasParent and each node has some particular color. I need to filter a tree by a color and extract the topmost elements (exclude nested elements after filtering).
Here is an example of my data:
The result I need is: [A, B, I].
I know how to implement basic tree filter that returns [A, B, I, J, L, O]:
SELECT DISTINCT ?s WHERE {
?s <http://looneytunes-graph.com/color> "yellow"^^xsd:string
}
Is there a way to implement such additional filtering? or do I need to rethink my solution and use something else instead of graph db (AWS Neptune)?
I'm testing it with https://sparql-playground.sib.swiss/data and the following data:
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://looneytunes-graph.com/A> <http://looneytunes-graph.com/color> "yellow"^^xsd:string .
<http://looneytunes-graph.com/B> <http://looneytunes-graph.com/color> "yellow"^^xsd:string .
<http://looneytunes-graph.com/C> <http://looneytunes-graph.com/color> "green"^^xsd:string .
<http://looneytunes-graph.com/D> <http://looneytunes-graph.com/color> "red"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/A> .
<http://looneytunes-graph.com/E> <http://looneytunes-graph.com/color> "blue"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/A> .
<http://looneytunes-graph.com/F> <http://looneytunes-graph.com/color> "blue"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/B> .
<http://looneytunes-graph.com/G> <http://looneytunes-graph.com/color> "green"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/B> .
<http://looneytunes-graph.com/H> <http://looneytunes-graph.com/color> "red"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/C> .
<http://looneytunes-graph.com/I> <http://looneytunes-graph.com/color> "yellow"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/C> .
<http://looneytunes-graph.com/J> <http://looneytunes-graph.com/color> "yellow"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/D> .
<http://looneytunes-graph.com/K> <http://looneytunes-graph.com/color> "green"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/D> .
<http://looneytunes-graph.com/L> <http://looneytunes-graph.com/color> "yellow"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/F> .
<http://looneytunes-graph.com/M> <http://looneytunes-graph.com/color> "red"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/G> .
<http://looneytunes-graph.com/N> <http://looneytunes-graph.com/color> "blue"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/G> .
<http://looneytunes-graph.com/O> <http://looneytunes-graph.com/color> "yellow"^^xsd:string ;
<http://looneytunes-graph.com/hasParent> <http://looneytunes-graph.com/I> .
SELECT DISTINCT ?s WHERE {
?s <http://looneytunes-graph.com/color> "yellow"^^xsd:string .
FILTER NOT EXISTS {
?s hasParent+ [<http://looneytunes-graph.com/color> "yellow"^^xsd:string] .
}
}
With this query you are filtering out the nodes having (a parent node having a parent node having...) a yellow parent node.

Translate nouns using SPARQL with Babelnet

The following query translates a word to a certain language:
SELECT DISTINCT ?translation WHERE {
?entries a lemon:LexicalEntry .
?entries rdfs:label "apple"#en .
?entries lemon:sense ?sense .
?sense lexinfo:translation ?translation .
filter contains(str(?translation),"HI")
}
But how can I retrieve the label for the translation, which is a LexicalSense as far I can tell
The way up and the way down is one and the same (as Heraclitus had said):
SELECT DISTINCT ?label WHERE {
?original_entry rdfs:label "apple"#en .
?original_entry lemon:sense ?original_sense .
?original_sense
lexinfo:translation
?translated_sense .
?translated_entry lemon:sense ?translated_sense .
?translated_entry rdfs:label ?label .
FILTER (lang(?label) = "hi")
}
Try it!
This page describes data model and provides some example queries.

print multiple path in rdf graph using sparql query

My data which simply denotes two paths from :a to :v and k respectively is as follows:
#prefix : <http://m/questions/19587520/sparql-path-between-two-instance/> .
:a :z :d.
:d :p :e .
:e :g :f .
:f :l :g .
:g :m :h .
:h :p :k .
:k :p :c .
:c :p :v .
:a :p :x.
:x :q :y.
:y :z :c.
:a :l :g .
:g :m :h .
:h :p :k .
The SPARQL queries that I tried are
String querygraph=
"PREFIX : <http://m/questions/19587520/sparql-path-between-two-instance/>" +
"SELECT ?start ?end (count(?mid) as ?length)" +
"WHERE {" +
" values (?start ?end) { (:a :c) " +
" } " +
" ?start (: |!:)+ ?mid . " +
" ?mid (: | !:)* ?end . " +
" } " +
" group by ?start ?end " +
" ORDER BY ASC(?length)";
String querygraph1=
"PREFIX : <http://monika/questions/19587520/sparql-path-between-two-instance/>" +
"select (count(?m) as ?length) " +
"WHERE {" +
" values (?s ?d) { (:a :c) " +
" } " +
"?s (:|!:)+ ?m ."+
" ?m (: | !:)* ?d . " +
"}" ;
In this I need to print and calculate length of path but the problem is there are two paths from :a to :c. My code is not able to differentiate between them, it calculates it as one. Please help me to print both paths separately with their length.
This is not possible in the general case using SPARQL. But if you you know of some intermediate node that needs to be visited you can add this part as part of the triple pattern.
Another option that may work is if you put the two paths in different named graphs:
#prefix : <http://m/questions/19587520/sparql-path-between-two-instance/> .
GRAPH :path1 {
:a :z :d.
:d :p :e .
:e :g :f .
:f :l :g .
:g :m :h .
:h :p :k .
:k :p :c .
:c :p :v .
}
GRAPH :path2 {
:a :p :x.
:x :q :y.
:y :z :c.
:a :l :g .
:g :m :h .
:h :p :k .
}
Then you could express a query against the first graph as:
PREFIX : <http://m/questions/19587520/sparql-path-between-two-instance/>
SELECT DISTINCT ?midI ?p ?midJ
FROM :path1
where {
VALUES (?begin ?end) { (:a :k) }
?begin !:* ?midI .
?midI ?p ?midJ .
?midJ !:* ?end .
}
This way you can avoid having the two paths cross each other. However, property paths in SPARQL cannot guarantee a shortest path (or all paths for that matter), only that there is one. You can count the length as well. There is a useful question here on stackoverflow that is related to this problem that I would recommend having a look at: Finding all steps in property path.