Creating triple for http://schema.org/workLocation - schema.org

I am creating a Turtle file which would contain triples for a particular individual of type schema:Person.
I am stuck in defining triples for the person's schema:workLocation. According to the documentation, the range of schema:workLocation includes schema:Place, and a place can have an schema:address which should have type schema:PostalAddress. I've created the following:
#prefix schema: <http://schema.org/> .
<http://www.example.com/ns/person/1> a schema:Person ;
schema:givenName "XXX" ;
schema:familyName "XXXX" ;
schema:addressCountry "USA" .
Is this the right way of describing an address? How do I specify the person's work location?

Let's work triple by triple, and then we can consider whether there are ways to clean up the presentation. First, you started with the prefix declaration and identifying a resource with type person:
#prefix schema: <http://schema.org/> .
#prefix : <http://stackoverflow.com/q/24891549/1281433/> .
:person1 a schema:Person .
Next, you want to add a work location. Well, the work location is going to be a thing, and will have either type Place or ContactPoint. Lets assume it's a place. Then we add:
:person1 schema:workLocation :place62 .
:place62 a schema:Place .
Now the place can be related to a PostalAddress by the schema:address property:
:place62 schema:address :address89 .
:address89 a schema:PostalAddress .
Now, there are lots of properties we might use to describe a PostalAddress. In this case, we might have something like (using the sample values from that page):
:address89 schema:addressLocality "Mountain View" .
:address89 schema:addressRegion "CA" .
:address89 schema:postalCode "94043" .
:address89 schema:streetAddress "1600 Amphitheathre Pkwy" .
Now a postal address also works with properties from ContactPoint, so you might want some of those, too, but you can define those in the same way. So now you have this data:
#prefix schema: <http://schema.org/> .
#prefix : <http://stackoverflow.com/q/24891549/1281433/> .
:person1 a schema:Person .
:person1 schema:workLocation :place62 .
:place62 a schema:Place .
:place62 schema:address :address89 .
:address89 a schema:PostalAddress .
:address89 schema:addressLocality "Mountain View" .
:address89 schema:addressRegion "CA" .
:address89 schema:postalCode "94043" .
:address89 schema:streetAddress "1600 Amphitheathre Pkwy" .
Unless you're going to reuse the place and address (which you might, if you're describing a bunch of People at the same location), you probably can use blank nodes instead of URI nodes. Doing that, and using some of the syntactic sugar that Turtle provides, you end up with:
#prefix schema: <http://schema.org/> .
#prefix : <http://stackoverflow.com/q/24891549/1281433/> .
:person1 a schema:Person ;
schema:workLocation [ a schema:Place ;
schema:address [ a schema:PostalAddress ;
schema:addressLocality "Mountain View" ;
schema:addressRegion "CA" ;
schema:postalCode "94043" ;
schema:streetAddress "1600 Amphitheathre Pkwy" ] ] .

Related

emacs prettify-symbols replacing characters at same point

I am using prettify-symbols to switch between the following words and shortcuts. The problem is that when the replacement is more than a single character, all letters are being inserted at the same point.
For instance when little is replaced I get a single l, rather than ll.
(defvar cluster
'(
("all" . "l") ("as" . "as") ("can" . "k")
("do" . "do") ("for" . "f") ("in" . "n")
("is" . "s") ("it" . "t") ("know" . "no")
("like" . "lk") ("little" . "ll") ("more" . "mo")
("some" . "so") ("than" . "n") ("that" . "ta")
("there" . "tr") ("this" . "th") ("time" . "ti")
("to" . "to") ("we" . "w") ("well" . "l")
("will" . "l") ("work" . "wk") ("you" . "u"))
"List of replacements for specific words.")
(defun prettify-cluster ()
"Set keywords and corresponding glyph."
(setq-local prettify-symbols-alist cluster))
The doc string of variable prettify-symbols-alist tells you that each alist entry is (SYMBOL . CHARACTER), where SYMBOL is a string.
In your alist, you have instead (STRING . STRING) entries.
prettify-symbols-alist is a variable defined in prog-mode.el.
Its value is nil
Automatically becomes buffer-local when set.
Documentation:
Alist of symbol prettifications.
Each element looks like (SYMBOL . CHARACTER), where the symbol
matching SYMBOL (a string, not a regexp) will be shown as
CHARACTER instead.
CHARACTER can be a character, or it can be a list or vector, in
which case it will be used to compose the new symbol as per the
third argument of compose-region.
Furthermore, if you use a list or vector of chars for CHARACTER then those chars are composed.
I think that what you want is maybe something like abbrev-mode?

Compare models for identity, but with variables? Construct with minus?

My team is implementing a variation of Ceusters's Referent Tracking. In our implementation, the original URI for an entity can be changed (to something containing a UUID), although a link to the original URI is always kept.
For example:
:Joey rdf:type :person .
:New_York_City rdf:type :locality .
:Joey :hometown :New_York_City .
might become:
:Joey :replacedWith :ABC123 .
:ABC123 rdf:type :person .
:New_York_City :replacedWith :FFF555 .
:FFF555 rdf:type :locality .
:ABC123 :hometown :FFF555 .
I am writing some Scala integration tests to see if our software does the referent tracking correctly.
Specifically, I know I should expect this CorrectPattern:
:Joey :replacedWith ?person .
?person rdf:type :person .
:New_York_City :replacedWith ?locale .
?locale rdf:type :locality .
?person :hometown ?locale .
But I don't know what the values of ?person and ?locale will be.
I can SPARQL ASK for CorrectPattern... that will tell me if the pattern is present. But I also want to confirm that nothing else has been added.
I thought I could CONSTRUCT { ?s ?p ?o }, MINUS out CorrectPattern, and check for an empty result, but Blazegraph is saying:
java.util.concurrent.ExecutionException: org.openrdf.query.MalformedQueryException: CONSTRUCT WHERE only permits statement patterns in the WHERE clause.
Any ideas? I want to check that the whole triple store contains nothing more and nothing less than CorrectPattern, but I think CorrectPattern must contain variables.
Once again bailed out by a comment from #AKSW, who doesn't seem to be especially obsessed with earning reputation points.
This CONSTRUCT, with an embedded SELECT, gets all triples from my model, depleted of any triples in the MINUS block, even when they contain variables. I'm pretty sure I can flesh out the MINUS block and finish my task.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SELECT ?s ?p ?o
WHERE
{ { ?s ?p ?o }
MINUS
{ ?s rdf:type ?o }
}
}
In order to determine that the triple-store contains only the triples which you expect and nothing more, you could test for the exact triples which you expect while simultaneously counting the number of triples which appear in the database before and after you run your program. If the difference in triples is higher or lower than you expect, you will know that you have some extraneous or missing data.
Use SPARQL SELECT Count function:
SELECT (count(?triples) as ?count)
WHERE {
?triples ?p ?o .}
Pseudocode:
val beforeTripleCount = countTriplesInDatabase()
//run your program, test for expected triples
val afterTripleCount = countTriplesInDatabase()
val diff = afterTripleCount - beforeTripleCount
//diff should be equal to the number of triples you expect to be added/removed
Additionally, if you are resistant to using variables in your tests, you could write additional queries to capture the URI of the node you have created, then add the results to your test queries using String concatenation.

Cannot access number key in Racket hash table?

So I'm trying to access a hash table in Racket, but I can not figure out why it's not working.
When I call hash->list on this hash:
{"26220765": [
{
"queue": "RANKED_SOLO_5x5",
"name": "Viktor's Marauders",
"participantId": "26220765",
"entries": [
{
"leaguePoints": 0,
"isFreshBlood": false,
"isHotStreak": false,
"division": "IV",
"isInactive": false,
"isVeteran": true,
"losses": 168,
"playerOrTeamName": "iGT500",
"playerOrTeamId": "32156611",
"wins": 173
},
{
"leaguePoints": 0,
"isFreshBlood": true,
"isHotStreak": false,
"division": "V",
"isInactive": false,
"isVeteran": false,
"losses": 255,
"playerOrTeamName": "dragdan",
"playerOrTeamId": "20430418",
"wins": 265
},
It returns
((|26220765| #hasheq((name . "Viktor's Marauders") (queue . "RANKED_SOLO_5x5") (tier . "PLATINUM") (entries . (#hasheq((playerOrTeamId . "32156611") (division . "IV") (playerOrTeamName . "iGT500") (leaguePoints . 0) (wins . 173) (losses . 168) (isHotStreak . #f) (isVeteran . #t) (isFreshBlood . #f) (isInactive . #f)) #hasheq((playerOrTeamId . "20430418") (division . "V") (playerOrTeamName . "dragdan") (leaguePoints . 0) (wins . 265) (losses . 255) (isHotStreak . #f) (isVeteran . #f)
I can not access the hash by using the key 26220765. I've tried defining it as summoner-id and passing it, i've tried using '26220765, it doesn't work. I don't understand why it's being displayed with vertical bars, and if I try '|26220765| or |26220765| it doesn't work either.
I had another hash table where I needed to access the hash "champions", and using 'champions worked, so why isn't this working?
This works:
#lang racket/base
(require json)
(define js (string->jsexpr "{\"123\": \"val\"}"))
js ;=> '#hasheq((|123| . "val"))
(hash-ref js '|123|) ;=> "val"
Do you have a similarly short example of what doesn't work for you?
p.s. You may find people more motivated to answer, if you take a moment to accept and/or upvote answers. Like Racket string to literal? and Getting a specific hash-table from a list in racket?.
In Racket there are different constructors for hash tables. The difference between them is that the hash table uses different comparators (eq? , equal? , eqv?, ...).
That's probably the reason why it doesn't work always like you would want it to.
The different hash tables in racket
In fact when making a hash table it has to know which comparator to use to check for equality. You could for example imagine a generic implementation where you have to pass your own lambda to be used as comparator.

How to translate words literally?

I want to translate the names of the businesses literally.
i.e :
FLAFEL ADAM I want to translate it to Hebrew,
F -> פ
L -> ל
A -> א
.
.
.
so it will be פלאפל אדם
both names have the same spelling ! I don't care a bout the meaning , I just want to have the same spelling in both languages !
How to do that ?
You could use table lookup, i.e. a table that translates every character from one language to another. In Obj-C, you could use a NSDictionary that you could initialize as
NSDictionary *table = #{#"F": #"פ",
#"L": #"ל",
#"A": #"א"
};
etc.
You can then do the translation e.g. as
NSString *translatedL = table[#"L"];
etc.

How to stop backtracking in Scala?

Suppose I am solving a problem (e.g. N-Queen) with backtracking. What if I want to find the only one (the 1-st) solution rather than all of them.
I guess I can do it imperatively (e.g. with a mutable boolean flag). I wonder how I can do it functionally.
While Scala's Option will work here, as two other answers have pointed out, a more idiomatic functional approach would be to use a "lazy list"—or a Stream, in Scala—to represent the set of solutions.
I've found myself writing code like this, for example:
trait Node[A] {
def children: Stream[A with Node[A]]
def dfs(f: A => Boolean): Stream[A] = this.children.flatMap {
child => if (f(child)) Stream(child) else child.dfs(f)
}
}
Now suppose I have a Board class that extends Node[Board] and that has an implementation of the children method that returns all valid boards with one additional piece. Suppose it also has some other useful stuff, like a size method, a companion object with an empty, etc.
I can then write the following to get a Stream of solutions:
val solutions = Board.empty.dfs(_.size == 8)
A Stream is lazy and only evaluates its head, so right now we've only searched the tree far enough to find the first solution. We can get this solution using head:
scala> solutions.head
res1: Board =
o . . . . . . .
. . . . o . . .
. . . . . . . o
. . . . . o . .
. . o . . . . .
. . . . . . o .
. o . . . . . .
. . . o . . . .
Or whatever. But I can also get other results if I want them:
scala> solutions(10)
res2: Board =
. o . . . . . .
. . . . . . o .
. . . . o . . .
. . . . . . . o
o . . . . . . .
. . . o . . . .
. . . . . o . .
. . o . . . . .
This searches just enough more of the tree to find the tenth solution, and then stops.
The big advantage of Stream over the Option approach is that I can get additional results if I need them, without paying more for the first.
Here's a simple case with a depth-first search that stops when it finds what it's looking for. It makes use of Option, as mentioned in Chris K's answer.
case class Tree[A](v: A, subtrees: Tree[A]*) {
def dfs(s: A): Option[A] = {
println("visiting " + v)
subtrees.foldLeft(if(v == s) Some(v) else None)((r, t) =>
if(r.isDefined)
r
else
t.dfs(s)
)
}
override def toString() = "Tree(%s%s%s)".format(v, if(subtrees.nonEmpty) ", " else "", subtrees.mkString(", "))
}
Usage:
scala> val t = Tree(1, Tree(2, Tree(3), Tree(4)), Tree(5, Tree(6), Tree(7)))
t: Tree[Int] = Tree(1, Tree(2, Tree(3), Tree(4)), Tree(5, Tree(6), Tree(7)))
The tree t looks like
1
/ \
2 5
/ \ / \
3 4 6 7
So we can search for an element and trace the nodes it visits:
scala> t.dfs(6)
visiting 1
visiting 2
visiting 3
visiting 4
visiting 5
visiting 6
res42: Option[Int] = Some(6)
Notice that we don't visit any more nodes after we find what we're looking for.
Assuming you're using a recursive search function, your function should either return a result (i.e. positioning of the queens) or an indication that no result could be found for that branch. Scala probably has an option/maybe type, you can use that. This advice is equally applicable to any functional language.