Query: What actors have played themselves?

I’m trying to find all the actors in the 21million movies dataset that have played themselves in a movie.

I did found one of them by hand and some Google searches: Neil Patrick Harris.
With the query below, I could show that indeed he played himself in a couple of movies.

{  
{  
  nph(func: eq(name@., "Neil Patrick Harris"))
    @filter(has(character.portrayed_in_films))
  {
    name@.
    uid
    character.portrayed_in_films {
    	performance.film {
      	name@.
    	}
      performance.actor @filter(eq(name@., "Neil Patrick Harris")) {
        name@.
        uid
      }
  	}
  }
}

The output is:

{
  "extensions": {
    "server_latency": {
      "parsing_ns": 39684,
      "processing_ns": 1812326,
      "encoding_ns": 1014961
    },
    "txn": {
      "start_ts": 22790001
    }
  },
  "data": {
    "nph": [
      {
        "name@.": "Neil Patrick Harris",
        "uid": "0x72a289",
        "character.portrayed_in_films": [
          {
            "performance.film": [
              {
                "name@.": "A Very Harold & Kumar 3D Christmas"
              }
            ],
            "performance.actor": [
              {
                "name@.": "Neil Patrick Harris",
                "uid": "0x1ae2c"
              }
            ]
          },
          {
            "performance.film": [
              {
                "name@.": "Harold & Kumar Go to White Castle"
              }
            ],
            "performance.actor": [
              {
                "name@.": "Neil Patrick Harris",
                "uid": "0x1ae2c"
              }
            ]
          },
          {
            "performance.film": [
              {
                "name@.": "Harold & Kumar Escape from Guantanamo Bay"
              }
            ],
            "performance.actor": [
              {
                "name@.": "Neil Patrick Harris",
                "uid": "0x1ae2c"
              }
            ]
          }
        ]
      }
    ]
  }
}

As you can see, while the name for the actor and the character match, the uid does not. So how could I find in general which actors have played roles in which the character had their own name?

Maybe @MichelDiz knows how to do this already?

By the way, thanks to @dmai I found this query:

But unfortunately it depends on the UIDs matching and even in that case it first requires knowing the name of the person, which defeats the purpose of my query.

I’d like to find “in general” what actors have played roles with named like them.

Yep, this dataset has a lot of duplicated data.

Like 4 Spielbergs

{
  me(func: eq(name@en, "Steven Spielberg"))  {
    name@en
  }
}

I’ll check your query as soon as possible.

You can store the name of the actor in a variable, and then use that variable for filtering in another query block.

{
  nph as var(func: eq(name@., "Neil Patrick Harris"))
  @filter(has(character.portrayed_in_films))
  {
    name as name@.
  }
  
  nph(func: uid(nph)) {
    uid
    character.portrayed_in_films {
      performance.film {
      	name@.
      }
      performance.actor @filter(eq(name@., val(name))) {
        name@.
        uid
      }
    }
  }
}

Looks like performance.character is the same uid as the actor nodes, so this query using @filter(uid(v)) would also work:

{
  nph as var(func: eq(name@., "Neil Patrick Harris"))
  @filter(has(character.portrayed_in_films))
  {
  }
  
  nph(func: uid(nph)) @cascade {
    uid
    character.portrayed_in_films {
      performance.film {
      	name@.
      }
      performance.character @filter(uid(nph)) {
        name@.
        uid
      }
    }
  }
}

This doesn’t really answer my question though, as I’d like to have a query that would return “Neil Patrick Harris” rather than taking it as an input.

I want to find “the actors that have played themselves”, not “times where Neil Patrick Harris has played himself”

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.