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

Merged with skosmos/master #1

Merged
merged 3 commits into from
Oct 30, 2017
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"components/jqueryui": "1.12.*",
"components/handlebars.js": "v1.3.0",
"davidstutz/bootstrap-multiselect": "v0.9.13",
"easyrdf/easyrdf": "0.9.*",
"easyrdf/easyrdf": "0.10.0-alpha.1",
"twig/twig": "1.29.*",
"twig/extensions": "1.4.*",
"twitter/bootstrap": "3.2.*",
Expand Down
4 changes: 2 additions & 2 deletions controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ public function vocabularyStatistics($request)
} else if (isset($vocabStats[$groupClass])) {
$ret['conceptGroups'] = array(
'class' => $groupClass,
'label' => isset($vocabStats[$groupClass]['label']) ? $vocabStats[$groupClass]['label'] : gettext(EasyRdf_Namespace::shorten($groupClass)),
'label' => isset($vocabStats[$groupClass]['label']) ? $vocabStats[$groupClass]['label'] : gettext(EasyRdf\RdfNamespace::shorten($groupClass)),
'count' => $vocabStats[$groupClass]['count'],
);
} else if (isset($vocabStats[$arrayClass])) {
$ret['arrays'] = array(
'class' => $arrayClass,
'label' => isset($vocabStats[$arrayClass]['label']) ? $vocabStats[$arrayClass]['label'] : gettext(EasyRdf_Namespace::shorten($arrayClass)),
'label' => isset($vocabStats[$arrayClass]['label']) ? $vocabStats[$arrayClass]['label'] : gettext(EasyRdf\RdfNamespace::shorten($arrayClass)),
'count' => $vocabStats[$arrayClass]['count'],
);
}
Expand Down
34 changes: 17 additions & 17 deletions model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Concept extends VocabularyDataObject
private $foundby;
/** Type of foundby match: 'alt', 'hidden' or 'lang' */
private $foundbytype;
/** the EasyRdf_Graph object of the concept */
/** the EasyRdf\Graph object of the concept */
private $graph;
private $clang;

Expand Down Expand Up @@ -48,8 +48,8 @@ class Concept extends VocabularyDataObject
* Initializing the concept object requires the following parameters.
* @param Model $model
* @param Vocabulary $vocab
* @param EasyRdf_Resource $resource
* @param EasyRdf_Graph $graph
* @param EasyRdf\Resource $resource
* @param EasyRdf\Graph $graph
*/
public function __construct($model, $vocab, $resource, $graph, $clang)
{
Expand Down Expand Up @@ -86,7 +86,7 @@ public function getType()
public function isGroup() {
$groupClass = $this->getVocab()->getConfig()->getGroupClassURI();
if ($groupClass) {
$groupClass = EasyRdf_Namespace::shorten($groupClass) !== null ? EasyRdf_Namespace::shorten($groupClass) : $groupClass;
$groupClass = EasyRdf\RdfNamespace::shorten($groupClass) !== null ? EasyRdf\RdfNamespace::shorten($groupClass) : $groupClass;
return in_array($groupClass, $this->getType());
}
return false;
Expand Down Expand Up @@ -124,7 +124,7 @@ public function getLabel()
foreach($this->resource->allLiterals('skos:prefLabel') as $label) {
// the label lang code is a subtag of the UI lang eg. en-GB - create a new literal with the main language
if ($label !== null && strpos($label->getLang(), $lang . '-') === 0) {
return EasyRdf_Literal::create($label, $lang);
return EasyRdf\Literal::create($label, $lang);
}
}

Expand Down Expand Up @@ -228,16 +228,16 @@ public function getMappingProperties()

$longUris = $this->resource->propertyUris();
foreach ($longUris as &$prop) {
if (EasyRdf_Namespace::shorten($prop) !== null) {
if (EasyRdf\RdfNamespace::shorten($prop) !== null) {
// shortening property labels if possible
$prop = $sprop = EasyRdf_Namespace::shorten($prop);
$prop = $sprop = EasyRdf\RdfNamespace::shorten($prop);
} else {
$sprop = "<$prop>";
}
// EasyRdf requires full URIs to be in angle brackets

if (in_array($prop, $this->MAPPING_PROPERTIES) && !in_array($prop, $this->DELETED_PROPERTIES)) {
$propres = new EasyRdf_Resource($prop, $this->graph);
$propres = new EasyRdf\Resource($prop, $this->graph);
$proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label(); // current language
$propobj = new ConceptProperty($prop, $proplabel);
if ($propobj->getLabel() !== null) {
Expand Down Expand Up @@ -321,20 +321,20 @@ public function getProperties()
}

foreach ($longUris as &$prop) {
if (EasyRdf_Namespace::shorten($prop) !== null) {
if (EasyRdf\RdfNamespace::shorten($prop) !== null) {
// shortening property labels if possible
$prop = $sprop = EasyRdf_Namespace::shorten($prop);
$prop = $sprop = EasyRdf\RdfNamespace::shorten($prop);
} else {
$sprop = "<$prop>";
}
// EasyRdf requires full URIs to be in angle brackets

if (!in_array($prop, $this->DELETED_PROPERTIES) || ($this->isGroup() === false && $prop === 'skos:member')) {
$propres = new EasyRdf_Resource($prop, $this->graph);
$propres = new EasyRdf\Resource($prop, $this->graph);
$proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label();
$superprop = $propres->get('rdfs:subPropertyOf') ? $propres->get('rdfs:subPropertyOf')->getURI() : null;
if ($superprop) {
$superprop = EasyRdf_Namespace::shorten($superprop) ? EasyRdf_Namespace::shorten($superprop) : $superprop;
$superprop = EasyRdf\RdfNamespace::shorten($superprop) ? EasyRdf\RdfNamespace::shorten($superprop) : $superprop;
}
$propobj = new ConceptProperty($prop, $proplabel, $superprop);

Expand All @@ -345,7 +345,7 @@ public function getProperties()

// searching for subproperties of literals too
foreach ($this->graph->allResources($prop, 'rdfs:subPropertyOf') as $subi) {
$suburi = EasyRdf_Namespace::shorten($subi->getUri()) ? EasyRdf_Namespace::shorten($subi->getUri()) : $subi->getUri();
$suburi = EasyRdf\RdfNamespace::shorten($subi->getUri()) ? EasyRdf\RdfNamespace::shorten($subi->getUri()) : $subi->getUri();
$duplicates[$suburi] = $prop;
}

Expand Down Expand Up @@ -491,7 +491,7 @@ public function getDate()
/**
* Gets the members of a specific collection.
* @param $coll
* @param array containing all narrowers as EasyRdf_Resource
* @param array containing all narrowers as EasyRdf\Resource
* @return array containing ConceptPropertyValue objects
*/
private function getCollectionMembers($coll, $narrowers)
Expand Down Expand Up @@ -532,7 +532,7 @@ public function getReverseResources($includeArrays) {
$reverseResources = $this->graph->resourcesMatching('skos:member', $this->resource);
if (isset($reverseResources)) {
$arrayClassURI = $this->vocab !== null ? $this->vocab->getConfig()->getArrayClassURI() : null;
$arrayClass = $arrayClassURI !== null ? EasyRdf_Namespace::shorten($arrayClassURI) : null;
$arrayClass = $arrayClassURI !== null ? EasyRdf\RdfNamespace::shorten($arrayClassURI) : null;
$superGroups = $this->resource->all('isothes:superGroup');
$superGroupUris = array_map(function($obj) { return $obj->getUri(); }, $superGroups);
foreach ($reverseResources as $reverseResource) {
Expand Down Expand Up @@ -570,7 +570,7 @@ public function getArrayProperties() {
/**
* Reads the literal language code and gets a name for it from Punic or alternatively
* tries to search for a gettext translation.
* @param EasyRdf_Literal $lit
* @param EasyRdf\Literal $lit
* @return string e.g. 'English'
*/
private function literalLanguageToString($lit) {
Expand Down Expand Up @@ -609,7 +609,7 @@ public function getAllLabels($property)
{
$labels = array();
// shortening property labels if possible, EasyRdf requires full URIs to be in angle brackets
$property = (EasyRdf_Namespace::shorten($property) !== null) ? EasyRdf_Namespace::shorten($property) : "<$property>";
$property = (EasyRdf\RdfNamespace::shorten($property) !== null) ? EasyRdf\RdfNamespace::shorten($property) : "<$property>";
foreach ($this->resource->allLiterals($property) as $lit) {
$labels[Punic\Language::getName($lit->getLang(), $this->getEnvLang())][] = new ConceptPropertyValueLiteral($lit, $property);
}
Expand Down
2 changes: 1 addition & 1 deletion model/ConceptPropertyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function getReifiedPropertyValues() {
$ret = array();
$props = $this->resource->propertyUris();
foreach($props as $prop) {
$prop = (EasyRdf_Namespace::shorten($prop) !== null) ? EasyRdf_Namespace::shorten($prop) : $prop;
$prop = (EasyRdf\RdfNamespace::shorten($prop) !== null) ? EasyRdf\RdfNamespace::shorten($prop) : $prop;
foreach ($this->resource->allLiterals($prop) as $val) {
if ($prop !== 'rdf:value' && $this->resource->get($prop)) { // shown elsewhere
$ret[gettext($prop)] = new ConceptPropertyValueLiteral($this->resource->get($prop), $prop);
Expand Down
2 changes: 1 addition & 1 deletion model/ConceptPropertyValueLiteral.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getContainsHtml() {
public function getLabel()
{
// if the property is a date object converting it to a human readable representation.
if ($this->literal instanceof EasyRdf_Literal_Date) {
if ($this->literal instanceof EasyRdf\Literal\Date) {
try {
$val = $this->literal->getValue();
return Punic\Calendar::formatDate($val, 'short');
Expand Down
6 changes: 3 additions & 3 deletions model/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class DataObject
/**
* Initializes the DataObject
* @param Model $model
* @param EasyRdf_Resource $resource
* @param EasyRdf\Resource $resource
*/
public function __construct($model, $resource)
{
if (!($model instanceof Model) || !($resource instanceof EasyRdf_Resource)) {
if (!($model instanceof Model) || !($resource instanceof EasyRdf\Resource)) {
throw new Exception('Invalid constructor parameter given to DataObject.');
}

Expand All @@ -40,7 +40,7 @@ public function __construct($model, $resource)
* @param Vocabulary $exvoc external vocabulary to query
* @param string $exuri resource URI
* @param string $lang language of label to query for
* @return EasyRdf_Literal label, or null if not found in vocabulary
* @return EasyRdf\Literal label, or null if not found in vocabulary
*/
protected function getExternalLabel($exvoc, $exuri, $lang)
{
Expand Down
52 changes: 26 additions & 26 deletions model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
/**
* Setting some often needed namespace prefixes
*/
EasyRdf_Namespace::set('skosmos', 'http://purl.org/net/skosmos#');
EasyRdf_Namespace::set('void', 'http://rdfs.org/ns/void#');
EasyRdf_Namespace::set('skosext', 'http://purl.org/finnonto/schema/skosext#');
EasyRdf_Namespace::set('isothes', 'http://purl.org/iso25964/skos-thes#');
EasyRdf_Namespace::set('mads', 'http://www.loc.gov/mads/rdf/v1#');
EasyRdf\RdfNamespace::set('skosmos', 'http://purl.org/net/skosmos#');
EasyRdf\RdfNamespace::set('void', 'http://rdfs.org/ns/void#');
EasyRdf\RdfNamespace::set('skosext', 'http://purl.org/finnonto/schema/skosext#');
EasyRdf\RdfNamespace::set('isothes', 'http://purl.org/iso25964/skos-thes#');
EasyRdf\RdfNamespace::set('mads', 'http://www.loc.gov/mads/rdf/v1#');

/**
* Model provides access to the data.
* @property EasyRdf_Graph $graph
* @property EasyRdf\Graph $graph
* @property GlobalConfig $globalConfig
*/
class Model
{
/** EasyRdf_Graph graph instance */
/** EasyRdf\Graph graph instance */
private $graph;
/** Namespaces from vocabularies configuration file */
private $namespaces;
Expand Down Expand Up @@ -96,7 +96,7 @@ private function initializeVocabularies()

private function parseVocabularies($filename)
{
$this->graph = new EasyRdf_Graph();
$this->graph = new EasyRdf\Graph();
$parser = new SkosmosTurtleParser();
$parser->parse($this->graph, file_get_contents($filename), 'turtle', $filename);
$this->namespaces = $parser->getNamespaces();
Expand All @@ -108,9 +108,9 @@ private function parseVocabularies($filename)

private function initializeNamespaces() {
foreach ($this->namespaces as $prefix => $fullUri) {
if ($prefix != '' && EasyRdf_Namespace::get($prefix) === null) // if not already defined
if ($prefix != '' && EasyRdf\RdfNamespace::get($prefix) === null) // if not already defined
{
EasyRdf_Namespace::set($prefix, $fullUri);
EasyRdf\RdfNamespace::set($prefix, $fullUri);
}
}
}
Expand Down Expand Up @@ -213,7 +213,7 @@ public function getTypes($vocid = null, $lang = null)

foreach ($result as $uri => $values) {
if (empty($values)) {
$shorteneduri = EasyRdf_Namespace::shorten($uri);
$shorteneduri = EasyRdf\RdfNamespace::shorten($uri);
if ($shorteneduri !== null) {
$trans = gettext($shorteneduri);
if ($trans) {
Expand Down Expand Up @@ -257,13 +257,13 @@ public function getRDF($vocid, $uri, $format)

if ($format == 'text/turtle') {
$retform = 'turtle';
$serialiser = new EasyRdf_Serialiser_Turtle();
$serialiser = new EasyRdf\Serialiser\Turtle();
} elseif ($format == 'application/ld+json' || $format == 'application/json') {
$retform = 'jsonld'; // serve JSON-LD for both JSON-LD and plain JSON requests
$serialiser = new EasyRdf_Serialiser_JsonLd();
$serialiser = new EasyRdf\Serialiser\JsonLd();
} else {
$retform = 'rdfxml';
$serialiser = new EasyRdf_Serialiser_RdfXml();
$serialiser = new EasyRdf\Serialiser\RdfXml();
}

if ($vocid !== null) {
Expand Down Expand Up @@ -398,7 +398,7 @@ public function searchConceptsAndInfo($params)
/**
* Creates dataobjects from an input array.
* @param string $class the type of class eg. 'Vocabulary'.
* @param array $resarr contains the EasyRdf_Resources.
* @param array $resarr contains the EasyRdf\Resources.
*/
private function createDataObjects($class, $resarr)
{
Expand All @@ -423,9 +423,9 @@ public function getVocabularies()
// register vocabulary ids as RDF namespace prefixes
$prefix = preg_replace('/\W+/', '', $voc->getId()); // strip non-word characters
try {
if ($prefix != '' && EasyRdf_Namespace::get($prefix) === null) // if not already defined
if ($prefix != '' && EasyRdf\RdfNamespace::get($prefix) === null) // if not already defined
{
EasyRdf_Namespace::set($prefix, $voc->getUriSpace());
EasyRdf\RdfNamespace::set($prefix, $voc->getUriSpace());
}

} catch (Exception $e) {
Expand All @@ -439,7 +439,7 @@ public function getVocabularies()

/**
* Returns the cached vocabularies from a category.
* @param EasyRdf_Resource $cat the category in question
* @param EasyRdf\Resource $cat the category in question
* @return array of vocabulary dataobjects
*/
public function getVocabulariesInCategory($cat)
Expand Down Expand Up @@ -563,7 +563,7 @@ public function guessVocabularyFromURI($uri)
}

// try to guess the URI space and look it up in the cache
$res = new EasyRdf_Resource($uri);
$res = new EasyRdf\Resource($uri);
$namespace = substr($uri, 0, -strlen($res->localName()));
if (array_key_exists($namespace, $this->vocabsByUriSpace)) {
$vocabs = $this->vocabsByUriSpace[$namespace];
Expand All @@ -583,9 +583,9 @@ public function guessVocabularyFromURI($uri)

/**
* Get the label for a resource, preferring 1. the given language 2. configured languages 3. any language.
* @param EasyRdf_Resource $res resource whose label to return
* @param EasyRdf\Resource $res resource whose label to return
* @param string $lang preferred language
* @return EasyRdf_Literal label as an EasyRdf_Literal object, or null if not found
* @return EasyRdf\Literal label as an EasyRdf\Literal object, or null if not found
*/
public function getResourceLabel($res, $lang)
{
Expand All @@ -604,11 +604,11 @@ private function fetchResourceFromUri($uri)
{
try {
// change the timeout setting for external requests
$httpclient = EasyRdf_Http::getDefaultHttpClient();
$httpclient = EasyRdf\Http::getDefaultHttpClient();
$httpclient->setConfig(array('timeout' => $this->getConfig()->getHttpTimeout()));
EasyRdf_Http::setDefaultHttpClient($httpclient);
EasyRdf\Http::setDefaultHttpClient($httpclient);

$client = EasyRdf_Graph::newAndLoad(EasyRdf_Utils::removeFragmentFromUri($uri));
$client = EasyRdf\Graph::newAndLoad(EasyRdf\Utils::removeFragmentFromUri($uri));
return $client->resource($uri);
} catch (Exception $e) {
return null;
Expand All @@ -619,9 +619,9 @@ public function getResourceFromUri($uri)
{
// prevent parsing errors for sources which return invalid JSON (see #447)
// 1. Unregister the legacy RDF/JSON parser, we don't want to use it
EasyRdf_Format::unregister('json');
EasyRdf\Format::unregister('json');
// 2. Add "application/json" as a possible MIME type for the JSON-LD format
$jsonld = EasyRdf_Format::getFormat('jsonld');
$jsonld = EasyRdf\Format::getFormat('jsonld');
$mimetypes = $jsonld->getMimeTypes();
$mimetypes['application/json'] = 0.5;
$jsonld->setMimeTypes($mimetypes);
Expand Down
2 changes: 1 addition & 1 deletion model/SkosmosTurtleParser.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class SkosmosTurtleParser extends EasyRdf_Parser_Turtle
class SkosmosTurtleParser extends EasyRdf\Parser\Turtle
{
private $bytePos = 0;
private $dataLength = null;
Expand Down
Loading