Skip to content

Instantly share code, notes, and snippets.

@e-maud
Last active January 30, 2017 08:21
Show Gist options
  • Save e-maud/0dd14a97403000c93f67 to your computer and use it in GitHub Desktop.
Save e-maud/0dd14a97403000c93f67 to your computer and use it in GitHub Desktop.

Garzoni People Search

About Person entities/mentions

How many person mentions
SELECT COUNT (distinct ?pm)
WHERE { ?pm a grz-owl:PersonMention .}
How many person entities
SELECT COUNT (distinct ?pe)
WHERE { ?pe a grz-owl:Person .}
Get number of mentions per entities
SELECT ?pe COUNT (distinct ?pm)
WHERE
{
    ?pm grz-owl:has_entityLink ?link .
    ?pe a grz-owl:Person .
    ?link  grz-owl:refers_to ?pe.
}
GROUP BY ?pe
Distribution of person entities per mention count (ok)
SELECT COUNT (distinct ?pe) AS ?NbPersonENtities ?mentionCount
WHERE
{
    SELECT ?pe COUNT (distinct ?pm) AS ?mentionCount
    WHERE
    {
        ?pm grz-owl:has_entityLink ?link .
        ?pe a grz-owl:Person .
        ?link  grz-owl:refers_to ?pe.
    }
GROUP BY ?pe
}
GROUP BY ?mentionCount
Role distribution of person being mentioned more than x time
SELECT ?roleType COUNT (distinct ?pe)
WHERE
{
    {
      ?pe grz-owl:role/grz-owl:value ?roleType .
    }
    {
    SELECT ?pe 
        WHERE
        {
            ?pm grz-owl:has_entityLink ?link .
            ?pe a grz-owl:Person .
            ?link  grz-owl:refers_to ?pe.
        }
        GROUP BY ?pe
    HAVING (count(distinct ?pm) > 10)
    }
}
Select the top-10 most “mentioned” persons
SELECT ?pe COUNT (distinct ?pm)
WHERE
{
    ?pm a grz-owl:PersonMention ;  grz-owl:has_entityLink ?link .
    ?pe a grz-owl:Person .
    ?link  grz-owl:refers_to ?pe.
}
GROUP BY ?pe
ORDER BY DESC (COUNT (distinct ?pm))
LIMIT 10
Get max number of personMention
SELECT MAX (?mentionCount) AS ?maxMention
WHERE
{
    SELECT ?pe (COUNT (distinct ?pm) AS ?mentionCount)
    WHERE
    {
        ?pm a grz-owl:PersonMention ;  grz-owl:has_entityLink ?link .
        ?pe a grz-owl:Person .
        ?link  grz-owl:refers_to ?pe.
    }
    GROUP BY ?pe
}
Get the person with the max number of mentions
Here come an awful query which could be done better I guess, or in two passes:
SELECT ?pe ?maxMention
WHERE
{
    {
    ?pe a grz-owl:Person .
    ?pm a grz-owl:PersonMention ;  grz-owl:has_entityLink ?link .
    ?link  grz-owl:refers_to ?pe.
    }
    {
    SELECT MAX (?mentionCount) AS ?maxMention
    WHERE
    {
        SELECT ?pe (COUNT (distinct ?pm) AS ?mentionCount)
        WHERE
        {
            ?pm a grz-owl:PersonMention ;  grz-owl:has_entityLink ?link .
            ?pe a grz-owl:Person .
            ?link  grz-owl:refers_to ?pe.
        }
    GROUP BY ?pe
    }
  }
}
GROUP BY ?pe ?maxMention
HAVING(count(distinct ?pm) = ?maxMention)
Select Person Entities with number of mention > x
SELECT ?pe (COUNT (distinct ?pm) AS ?countMention)
    WHERE
    {
        ?pm a grz-owl:PersonMention ;  grz-owl:has_entityLink ?link .
        ?pe a grz-owl:Person .
        ?link  grz-owl:refers_to ?pe.
    }
    GROUP BY ?pe
HAVING (count(distinct ?pm) > 5)
ORDER BY DESC (count(distinct ?pm))
How many Person have more than 1 mention
SELECT (COUNT (distinct ?pe))
WHERE
{
SELECT ?pe
    WHERE
    {
        ?pe a grz-owl:Person ; grz-owl:has_mention ?link .
        ?link  grz-owl:is_entityLink_of ?pm.
    }
    GROUP BY ?pe
    HAVING (COUNT (distinct ?pm) > 1)
}
Average number of PersonMentions per Person Entities
SELECT AVG(?mentionCount)
WHERE
{
    SELECT ?pe (COUNT (distinct ?pm) AS ?mentionCount)
    WHERE
    {
        ?pm a grz-owl:PersonMention ;  grz-owl:has_entityLink ?link .
        ?pe a grz-owl:Person .
        ?link  grz-owl:refers_to ?pe.
    }
    GROUP BY ?pe
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment