Commit afb22986 authored by Volker Krause's avatar Volker Krause
Browse files

Add basic JSON-LD @graph expansion

Result isn't entirely propagated yet due to a pending API change for that.
This also doesn't do any reference resolving etc. Should nevertheless
already help PBI a bit.
parent cbd43d44
[{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "/#organization",
"name": "A car company",
"url": "/",
"logo": {
"@type": "ImageObject",
"@id": "/#logo",
"url": "/favicon.png",
"caption": "Creating cars"
},
"image": {
"@id": "/#logo"
}
},
{
"@type": "WebSite",
"@id": "/#website",
"url": "/",
"name": "Car Company",
"publisher": {
"@id": "/#organization"
},
"potentialAction": {
"@type": "SearchAction",
"target": "/?s={search_term_string}",
"query-input": "required name=search_term_string"
}
},
{
"@type": "ImageObject",
"@id": "/#primaryimage",
"url": "/logo@2x.png"
},
{
"@type": "WebPage",
"@id": "/#webpage",
"url": "/",
"name": "Some car company",
"isPartOf": {
"@id": "/#website"
},
"about": {
"@id": "/#organization"
},
"primaryImageOfPage": {
"@id": "/#primaryimage"
},
"datePublished": "2019-12-20T12:18:20+00:00",
"dateModified": "2020-02-06T08:33:55+00:00"
}
]
}]
[
{
"@context": "http://schema.org",
"@type": "Organization",
"name": "A car company",
"url": "/"
}
]
......@@ -327,7 +327,20 @@ static void filterRecursive(QJsonObject &obj)
}
}
QJsonArray JsonLdImportFilter::filterObject(const QJsonObject& obj)
static QJsonArray graphExpand(const QJsonObject &obj)
{
QJsonArray result;
const auto graph = obj.value(QLatin1String("@graph")).toArray();
for (const auto &o : graph) {
const auto a = JsonLdImportFilter::filterObject(o.toObject());
std::copy(a.begin(), a.end(), std::back_inserter(result));
}
return result;
}
QJsonArray JsonLdImportFilter::filterObject(const QJsonObject &obj)
{
QStringList types;
const auto typeVal = obj.value(QLatin1String("@type"));
......@@ -343,6 +356,10 @@ QJsonArray JsonLdImportFilter::filterObject(const QJsonObject& obj)
}
// TODO consider additionalTypes property
if (types.isEmpty()) {
return graphExpand(obj);
}
QJsonArray results;
for (const auto &type : types) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment