Analyzing Topics

Topics are a key feature when working with Facebook topic data in PYLON. Topics are inferred from the content of stories created by authors. Instead of attempting to filter by long lists of keywords, topics give you a strong concept in the Facebook graph to work with. Topics exist for everything from brands to movies to locations!

You can use the topics inferred from content in both your analysis query filters and as targets to be analyzed.

tip icon

Remember when you write any query you need to consider whether you are looking for stories, engagements or both. The targets in the fb.topics.* namespace represents topics found in original stories, whereas the fb.parent.topics.* namespace represents topics found in stories which are the parent of an engagement.

You can read our introduction to Facebook topic data for more details.

Analysis Query Filters

Topics give you a great way to subset your data for further analysis.

When you submit an analysis query you can provide an optional filter using the filter parameter. This parameter accepts CSDL allowing you to subset the data in your index before the analysis is run.

Topic Categories

Topics on the Facebook graph are grouped into high-level categories. This is extremely useful is you're aiming to capture a broad set of data into your index.

To filter by topic category you make use of the fb.topics.category and fb.parent.topics.category targets, depending on whether you want to filter to stories or engagements.

For example if you'd like to filter to stories that relate to cars:

fb.topics.category == "Cars"

Of course if your index doesn't contain much content that relates to cars you will receive redacted results!

Or, for example you might want to filter to engagements on stories about movies using multiple categories:

fb.parent.topics.category IN "Movie,Movie Genre,Movie character"

If you're looking to analyze the most engaged with shared movie links:

{
    "analysis_type": "freqDist",
    "filter": "fb.parent.topics.category IN \"Movie,Movie Genre,Movie character\"",
    "parameters": {
        "target": "links.url",
        "threshold": 5
    }
}

Individual Topics

You can also use individual topics for your query filters. You can do so by ID or name.

Again there are targets for stories and engagements - fb.topics.name and fb.parent.topics.name respectively.

For example if you'd like to filter to stories that relate to a well-known brand:

fb.topics.name == "BMW"

Or, for example you might want to filter to engagements on a number of brands:

fb.parent.topics.name IN "BMW,Nissan,Renault"

You can also use topic IDs using fb.topic_ids and fb.parent.topic_ids:

fb.parent.topic_ids in [22893372268,333711736686957,116825037862]

Equally you can use the fb.topics.category_name and fb.parent.topics.category_name targets which expose topics with their categories in one target:

fb.topics.name == "Cars|BMW"

As the topic category and name targets are tokenized for query filtering you can also make use of string operators such as contains and contains_any. So for example you could write the following filter to look for any topics with brands in their name:

fb.topics.name contains_any "BMW,Nissan,Renault"

This filter would pick up topics such as "BMW UK" and "BMW Ireland" for instance.

tip icon

Should I use topic names or IDs?

Note that the name of a topic is determined by the page name on Facebook. There's a chance the page owner may choose to update the name of their page, this change will be reflected in the topic's name.

Topic names are great for exploration, but we recommend you use Topic IDs for production work. (Note there are no IDs for topic categories.)

Analysis Targets

You can also use topics categories and individual topics in you analysis as targets for analysis.

Topic Categories

A great place to start exploring recorded data is by analyzing the top topic categories found. This is a good way to check the quality of the data you've recorded.

For instance to find the top topic categories found in stories:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.topics.category",
        "threshold": 10
    }
}

You can analyze for topic categories found in engaged with stories by using the fb.parent.topics.category target.

Individual Topics

You can also analyze to find the top individual topics found in stories and engaged with stories.

For instance to find the top topics found in stories:

{
    "analysis_type": "freqDist",
    "parameters": {
        "target": "fb.topics.name",
        "threshold": 10
    }
}

You can analyze for topics found in engaged with stories by using the fb.parent.topics.name target.

You can also analyze topics IDs using fb.topic_ids and fb.parent.topic_ids targets.

Using Topics in both Query Filters and as Analysis Targets

You can make use of topics in your query filter and as your target for analysis:

{
    "analysis_type": "freqDist",
    "filter": "fb.topics.name IN \"BMW,Nissan,Renault\"",
    "parameters": {
        "target": "fb.topics.name",
        "threshold": 5
    }
}

But what does this mean?

This query is saying first filter my dataset to interactions that contain at least one of the three brands, then analyze this set of data for the top topics.

Of course the result is likely to be that the three brands will be in the top topics as you've filtered to these!

Topics that are returned in the results are topics that have been mentioned alongside one of the three topics within the same story.

Relating Topics to Topic Categories

Often you'll want to retrieve a list of topics which are from certain category. You could attempt to do so with the following query:

{
    "analysis_type": "freqDist",
    "filter": "fb.topics.category IN \"Cars\"",
    "parameters": {
        "target": "fb.topics.name",
        "threshold": 5
    }
}

Note though that this will analyze all topics that appear in stories which mention cars, but a story may mention multiple topics (alongside a car-related topic) so in fact your query will return topics some which are car-related and some that are not.

Here the fb.topics.category_name and fb.parent.topics.category_name are very useful.

{
    "analysis_type": "freqDist",
    "filter": "fb.topics.category IN \"Cars\"",
    "parameters": {
        "target": "fb.topics.category_name",
        "threshold": 5
    }
}

This modified query will return a list of topics, each with its parent category name, allowing you to pick out just the topics that relate to cars.