Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding concept data as jsonld to page source, related to #673 #674

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function getLabel()
return EasyRdf\Literal::create($label, $lang);
}
}

// 4. label in any language, including literal with empty language tag
$label = $this->resource->label();
if ($label !== null) {
Expand Down Expand Up @@ -262,6 +262,7 @@ public function getMappingProperties()

if ($response) {
$ret[$prop]->addValue(new ConceptMappingPropertyValue($this->model, $this->vocab, $response, $prop), $this->clang);
$this->graph->parse($response->getGraph()->serialise("rdfxml"), "rdfxml");
continue;
}
}
Expand Down Expand Up @@ -479,11 +480,11 @@ public function getDate()
$ret = '';
if ($this->resource->get('dc:modified')) {
$modified = (string) $this->resource->get('dc:modified');
$ret = gettext('skosmos:modified') . ' ' . $modified;
$ret = gettext('skosmos:modified') . ' ' . $modified;
}
if ($this->resource->get('dc:created')) {
$created .= (string) $this->resource->get('dc:created');
$ret .= ' ' . gettext('skosmos:created') . ' ' . $created;
$ret .= ' ' . gettext('skosmos:created') . ' ' . $created;
}
}
return $ret;
Expand Down Expand Up @@ -594,7 +595,7 @@ public function getForeignLabels()
foreach ($labels as $lit) {
// filtering away subsets of the current language eg. en vs en-GB
if ($lit->getLang() != $this->clang && strpos($lit->getLang(), $this->getEnvLang() . '-') !== 0) {
$prop = in_array($lit, $prefLabels) ? 'skos:prefLabel' : 'skos:altLabel';
$prop = in_array($lit, $prefLabels) ? 'skos:prefLabel' : 'skos:altLabel';
$ret[$this->literalLanguageToString($lit)][] = new ConceptPropertyValueLiteral($lit, $prop);
}
}
Expand All @@ -617,4 +618,36 @@ public function getAllLabels($property)
ksort($labels);
return $labels;
}

/**
* Dump concept graph as JSON-LD.
*/
public function dumpJsonLd() {

$context = array(
'skos' => 'http://www.w3.org/2004/02/skos/core#',
'isothes' => 'http://purl.org/iso25964/skos-thes#',
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
'owl' => 'http://www.w3.org/2002/07/owl#',
'dct' => 'http://purl.org/dc/terms/',
'dc11' => 'http://purl.org/dc/elements/1.1/',
'uri' => '@id',
'type' => '@type',
'lang' => '@language',
'value' => '@value',
'graph' => '@graph',
'label' => 'rdfs:label',
'prefLabel' => 'skos:prefLabel',
'altLabel' => 'skos:altLabel',
'hiddenLabel' => 'skos:hiddenLabel',
'broader' => 'skos:broader',
'narrower' => 'skos:narrower',
'related' => 'skos:related',
'inScheme' => 'skos:inScheme',
);
$compactJsonLD = \ML\JsonLD\JsonLD::compact($this->graph->serialise('jsonld'), json_encode($context));
$results = \ML\JsonLD\JsonLD::toString($compactJsonLD);

return $results;
}
}
5 changes: 5 additions & 0 deletions view/scripts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var uriSpace = "{{ request.vocab.uriSpace }}";
var showNotation = {% if request.vocab and request.vocab.config.showNotation == false %}false{% else %}true{% endif %};
</script>

{% if request.page == 'page' and search_results and search_results|length == 1 %}
<script type="application/ld+json">
{{ search_results|first.dumpJsonLd|raw }}
</script>
{% endif %}
<script type="text/javascript" src="vendor/components/jquery/jquery.min.js"></script>
<script type="text/javascript" src="vendor/components/jqueryui/jquery-ui.min.js"></script>
<script type="text/javascript" src="vendor/components/handlebars.js/handlebars.min.js"></script>
Expand Down