Overview
An XPath is an expression that points at part of a page. Classification providers that accept one read only the matching part of the page instead of the whole document, so navigation, adverts, recommended articles, comments and legal boilerplate do not influence the classification.Prerequisites:
- Access to the Permutive Dashboard
- A classification provider that supports XPath selectors — its configuration shows a Set XPath field. IBM Watson and Permutive Brand Safety both do
Why Set an XPath
Most article pages carry far more text than the article itself. A page about a cycling race that also lists ten recommended stories about politics can come back classified as politics, because the classifier sees all of it. Pointing the provider at the element that wraps the article body removes that noise. It usually improves the categories you get back, and on providers billed by content volume it reduces the amount of text sent for classification.Where XPaths Are Configured
Finding an XPath
1
Open a typical article
Pick a page that represents the template you want to classify, not an unusual one.
2
Inspect the article body
Right-click a paragraph in the middle of the article and choose Inspect to open your browser’s developer tools.
3
Walk up to the wrapping element
In the elements panel, move up the tree until the highlighted region covers the article and nothing else. Stop before it starts including the header, sidebar or footer.
4
Copy the XPath
Right-click that element and choose Copy > Copy XPath.
5
Generalise it
The copied expression is an absolute path such as
/html/body/div[3]/div[2]/main/article, which breaks as soon as the page structure changes. Shorten it to something that describes the element instead — //article, //main, or //div[@class="article-body"].Checking a Selector
1
Open the preview
Navigate to Contextual > Catalog, hover over the provider tile and click Preview.
2
Enter a URL and expand Advanced settings
Enter an article URL from your site, then expand Advanced settings and paste the XPath.
3
Classify
Click Classify and review the results.
4
Compare
Clear the XPath and classify the same URL again. The difference tells you whether the selector is helping.
Only the first match is read. If an expression matches several elements, the provider classifies the first one and ignores the rest. A broad selector such as
//div will quietly classify one fragment of the page. Prefer an expression that resolves to exactly one element.Next Steps
Previewing Classifications
Test how providers classify your content
Enabling Classification Providers
Enable and configure NLP classification providers