<commit_before><?php


namespace ANDS\Registry\Providers\RIFCS;


use ANDS\RecordData;
use ANDS\RegistryObject;
use ANDS\Registry\Providers\MetadataProvider;
use ANDS\Registry\Providers\RIFCSProvider;
use ANDS\Registry\Providers\RelationshipProvider;
use ANDS\Util\Config;
use MinhD\SolrClient\SolrClient;
use MinhD\SolrClient\SolrSearchResult;
use ANDS\Util\XMLUtil;


/**
 * Class JsonLDProvider
 * @package ANDS\Registry\Providers
 */

class JsonLDProvider implements RIFCSProvider
{

    public function base_url() {
        return Config::get('app.default_base_url');
    }

    public static function process(RegistryObject $record){

        $base_url = Config::get('app.default_base_url');

        $data = MetadataProvider::get($record);
        $json_ld = new JsonLDProvider();
        $json_ld->{'@context'} = "http://schema.org/";
        if($record->type=='dataset'|| $record->type=='collection') {
            $json_ld->{'@type'} = "Dataset";
        }
        $json_ld->name = $record->title;
        $json_ld->accountablePerson = self::getAccountablePerson($record,$data);
        $json_ld->author = self::getAuthor($record,$data);
        $json_ld->alternateName = self::getAlternateName($record,$data);
        $json_ld->alternativeHeadline = self::getAlternateName($record,$data);
        $json_ld->version = self::getVersion($record,$data);
        $json_ld->description = self::getDescriptions($record,$data);
        $json_ld->sourceOrganization = array("@type"=>"Organization","name"=>$record->group);
        $json_ld->url = self::base_url() ."view?key=".$record->key;
        $json_ld = (object) array_filter((array) $json_ld);
        return '<script type="application/ld+json">'.json_encode($json_ld).'<script>';
    }

    public static function get(RegistryObject $record){
        return ;
    }

    public static function getAuthor(
        RegistryObject $record,
        $data = null
    )
    {
        $authorArray = array("IsPrincipalInvestigatorOf","author","coInvestigator");
        $authorArray2 = array("isOwnedBy","hasCollector");

        if (!$data) {
            $data = MetadataProvider::getSelective($record, ['recordData']);
        }
        $author = [];

        foreach (XMLUtil::getElementsByXPath($data['recordData'],
            'ro:registryObject/ro:' . $record->class . '/ro:citationInfo/ro:citationMetadata/ro:contributor') AS $contributor) {
            $name = (array)$contributor;
            $author[]= array("@type"=>"Person","name"=>(implode(" ",$name['namePart'])));
        };

       // if(count($author)>0) return $author;

        $relationships = RelationshipProvider::getMergedRelationships($record);

        foreach ($relationships as $relation) {
            if (($relation->prop("to_class") == "party" || $relation->prop("to_related_info_type") == "party")
                && (in_array($relation->prop('relation_type'),$authorArray) || count(array_intersect($authorArray, $relation->prop('relation_type')))>0)
            ) {
                if($relation->prop("to_type")=='group'|| $relation->prop("to_related_info_type")=='group'){
                    $type = "Organization";
                } else{
                    $type = "Person";
                }

                if($relation->prop("to_title") != ""){
                    $author[] = array("@type"=>$type,"name"=>$relation->prop("to_title"),"url"=>self::base_url() ."view?key=".$relation->prop("to_key"));
                }else{
                    $identifier =array(
                        "@type"=> "PropertyValue",
                        "propertyID"=> $relation->prop("to_identifier_type"),
                        "value"=> $relation->prop("to_identifier")
                    );
                    $author[] = array("@type"=>$type,"name"=>$relation->prop("relation_to_title"),"identifier"=>$identifier);
                }
            }
        }

     //   if(count($author)>0) return $author;

        foreach ($relationships as $relation) {<commit_msg>added creator json-ld elements<commit_after><?php


namespace ANDS\Registry\Providers\RIFCS;


use ANDS\RecordData;
use ANDS\RegistryObject;
use ANDS\Registry\Providers\MetadataProvider;
use ANDS\Registry\Providers\RIFCSProvider;
use ANDS\Registry\Providers\RelationshipProvider;
use ANDS\Util\Config;
use MinhD\SolrClient\SolrClient;
use MinhD\SolrClient\SolrSearchResult;
use ANDS\Util\XMLUtil;


/**
 * Class JsonLDProvider
 * @package ANDS\Registry\Providers
 */

class JsonLDProvider implements RIFCSProvider
{

    public function base_url() {
        return Config::get('app.default_base_url');
    }

    public static function process(RegistryObject $record){

        $base_url = Config::get('app.default_base_url');

        $data = MetadataProvider::get($record);
        $json_ld = new JsonLDProvider();
        $json_ld->{'@context'} = "http://schema.org/";
        if($record->type=='dataset'|| $record->type=='collection') {
            $json_ld->{'@type'} = "Dataset";
        }
        $json_ld->name = $record->title;
        $json_ld->accountablePerson = self::getAccountablePerson($record,$data);
        $json_ld->author = self::getAuthor($record,$data);
        $json_ld->creator = self::getCreator($record,$data);
        $json_ld->alternateName = self::getAlternateName($record,$data);
        $json_ld->alternativeHeadline = self::getAlternateName($record,$data);
        $json_ld->version = self::getVersion($record,$data);
        $json_ld->description = self::getDescriptions($record,$data);
        $json_ld->sourceOrganization = array("@type"=>"Organization","name"=>$record->group);
        $json_ld->url = self::base_url() ."view?key=".$record->key;
        $json_ld = (object) array_filter((array) $json_ld);
        return '<script type="application/ld+json">'.json_encode($json_ld).'<script>';
    }

    public static function get(RegistryObject $record){
        return ;
    }
    public static function getCreator(
        RegistryObject $record,
        $data = null
    )
    {
        $creatorArray = array("IsPrincipalInvestigatorOf","author","coInvestigator","isOwnedBy","hasCollector");

        if (!$data) {
            $data = MetadataProvider::getSelective($record, ['recordData']);
        }
        $creator = [];

        foreach (XMLUtil::getElementsByXPath($data['recordData'],
            'ro:registryObject/ro:' . $record->class . '/ro:citationInfo/ro:citationMetadata/ro:contributor') AS $contributor) {
            $name = (array)$contributor;
            $creator[]= array("@type"=>"Person","name"=>(implode(" ",$name['namePart'])));
        };

        if(count($creator)>0) return $creator;

        $relationships = RelationshipProvider::getMergedRelationships($record);

        foreach ($relationships as $relation) {
            foreach ($creatorArray as $creatorType)
            if (($relation->prop("to_class") == "party" || $relation->prop("to_related_info_type") == "party")
                && ($relation->prop('relation_type') == $creatorType) || in_array($creatorType, $relation->prop('relation_type'))
            ) {
                if($relation->prop("to_type")=='group'|| $relation->prop("to_related_info_type")=='group'){
                    $type = "Organization";
                } else{
                    $type = "Person";
                }

                if($relation->prop("to_title") != ""){
                    $creator[] = array("@type"=>$type,"name"=>$relation->prop("to_title"),"url"=>self::base_url() ."view?key=".$relation->prop("to_key"));
                }else{
                    $identifier =array(
                        "@type"=> "PropertyValue",
                        "propertyID"=> $relation->prop("to_identifier_type"),
                        "value"=> $relation->prop("to_identifier")
                    );
                    $creator[] = array("@type"=>$type,"name"=>$relation->prop("relation_to_title"),"identifier"=>$identifier);
                }

                return $creator;

            }
        }
        return $creator;
    }

    public static function getAuthor(
        RegistryObject $record,
        $data = null
    )
    {
        $authorArray = array("IsPrincipalInvestigatorOf","author","coInvestigator");
        $authorArray2 = array("isOwnedBy","hasCollector");

        if (!$data) {
            $data = MetadataProvider::getSelective($record, ['recordData']);
        }
        $author = [];

        foreach (XMLUtil::getElementsByXPath($data['recordData'],
            'ro:registryObject/ro:' . $record->class . '/ro:citationInfo/ro:citationMetadata/ro:contributor') AS $contributor) {
            $name = (array)$contributor;
            $author[]= array("@type"=>"Person","name"=>(implode(" ",$name['namePart'])));
        };

        if(count($author)>0) return $author;

        $relationships = RelationshipProvider::getMergedRelationships($record);

        foreach ($relationships as $relation) {
            if (($relation->prop("to_class") == "party" || $relation->prop("to_related_info_type") == "party")
                && (in_array($relation->prop('relation_type'),$authorArray) || count(array_intersect($authorArray, $relation->prop('relation_type')))>0)
            ) {
                if($relation->prop("to_type")=='group'|| $relation->prop("to_related_info_type")=='group'){
                    $type = "Organization";
                } else{
                    $type = "Person";
                }

                if($relation->prop("to_title") != ""){
                    $author[] = array("@type"=>$type,"name"=>$relation->prop("to_title"),"url"=>self::base_url() ."view?key=".$relation->prop("to_key"));
                }else{
                    $identifier =array(
                        "@type"=> "PropertyValue",
                        "propertyID"=> $relation->prop("to_identifier_type"),
                        "value"=> $relation->prop("to_identifier")
                    );
                    $author[] = array("@type"=>$type,"name"=>$relation->prop("relation_to_title"),"identifier"=>$identifier);
                }
            }
        }

        if(count($author)>0) return $author;

        foreach ($relationships as $relation) {
            foreach($authorArray2 as $authorType)
{'fraction_non_alphanumeric': 0.17234996102883865, 'fraction_numerical': 0.0009742790335151987, 'mean_word_length': 2.7031024531024532, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2013049', 'n_tokens_mistral': 3052, 'n_tokens_neox': 2910, 'n_words': 404}