<commit_before><?php if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class Spatial_Extension extends ExtensionBase
{

    function __construct($ro_pointer)
    {
        parent::__construct($ro_pointer);
    }

    function determineSpatialExtents()
    {
        $extents = array();

        $sxml = $this->ro->getSimpleXML();
        $sxml->registerXPathNamespace("ro", RIFCS_NAMESPACE);
        $spatial_elts = $sxml->xpath('//ro:spatial');

        foreach ($spatial_elts AS $spatial) {
            $north = null;
            $south = null;
            $west = null;
            $east = null;
            $type = $spatial["type"];
            $value = preg_replace('!\s+!', ' ', (string)$spatial);
            if ($type == 'kmlPolyCoords' || $type == 'gmlKmlPolyCoords') {
                if ($this->isValidKmlPolyCoords($value)) {
                    $north = -90;
                    $south = 90;
                    $west = 180;
                    $east = -180;
                    $tok = strtok($value, " ");
                    while ($tok !== false) {
                        $keyValue = explode(",", $tok);
                        //$msg = $msg.'<br/>lat ' .$keyValue[1]. ' long '.$keyValue[0];
                        if (is_numeric($keyValue[1]) && is_numeric($keyValue[0])) {

                            $lng = floatval($keyValue[0]);
                            $lat = floatval($keyValue[1]);
                            //$msg = $msg.'<br/>lat ' .$lat. ' long '.$lng;
                            if ($lat > $north) {
                                $north = $lat;
                            }
                            if ($lat < $south) {
                                $south = $lat;
                            }
                            if ($lng < $west) {
                                $west = $lng;
                            }
                            if ($lng > $east) {
                                $east = $lng;
                            }
                        }
                        $tok = strtok(" ");
                    }

                }
            } elseif ($type == 'iso19139dcmiBox') {
                //northlimit=-23.02; southlimit=-25.98; westlimit=166.03; eastLimit=176.1; projection=WGS84
                $north = null;
                $south = null;
                $west = null;
                $east = null;
                $tok = strtok($value, ";");
                while ($tok !== false) {
                    $keyValue = explode("=", $tok);
                    if (strtolower(trim($keyValue[0])) == 'northlimit' && is_numeric($keyValue[1])) {
                        $north = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'southlimit' && is_numeric($keyValue[1])) {
                        $south = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'westlimit' && is_numeric($keyValue[1])) {
                        $west = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'eastlimit' && is_numeric($keyValue[1])) {
                        $east = floatval($keyValue[1]);
                    }
                    $tok = strtok(";");
                }
            } elseif ($type == 'iso19139dcmiPoint' || $type == 'dcmiPoint') //"name=<NAME>; east=160.0; north=-40.0"
            {
                //northlimit=-23.02; southlimit=-25.98; westlimit=166.03; eastLimit=176.1; projection=WGS84
                $north = null;
                $south = null;
                $west = null;
                $east = null;
                $tok = strtok($value, ";");
                while ($tok !== false) {
                    $keyValue = explode("=", $tok);
                    if (strtolower(trim($keyValue[0])) == 'north' && is_numeric($keyValue[1])) {
                        $north = floatval($keyValue[1]);
                        $south = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'east' && is_numeric($keyValue[1])) {
                        $west = floatval($keyValue[1]);
                        $east = floatval($keyValue[1]);
                    }
                    $tok = strtok(";");
                }
            } elseif ($type == 'iso31661' || $type == 'iso31662' || $type == 'iso3166') //"name=<NAME>; east=160.0; north=-40.0"
            {

                $north = null;
                $south = null;
                $west = null;
                $east = null;

                $gCoords = $this->getExtentFromGoogle(trim($value), $type);

                if ($gCoords) {
                    $north = floatval($gCoords['north']);
                    $south = floatval($gCoords['south']);
                    $west = floatval($gCoords['west']);
                    $east = floatval($gCoords['east']);
                }
            }
            //$msg = $msg.'<br/> north:'.$north.' south:'.$south.' west:'.$west.' east:'.$east;
            if ($this->isValidWSEN($west, $south, $east, $north)) {
                $extents[] = $west . " " . $south . " " . $east . " " . $north;
            }

        }
        return $extents;
    }

    function getLocationAsLonLats()
    {
        $coords = array();

        $sxml = $this->ro->getSimpleXML();
        $sxml->registerXPathNamespace("ro", RIFCS_NAMESPACE);
        $spatial_elts = $sxml->xpath('//ro:spatial');

        foreach ($spatial_elts AS $spatial) {

            $type = $spatial["type"];
            $value = preg_replace('!\s+!', ' ', (string)$spatial);

            if ($this->isValidKmlPolyCoords($value) && ($type == 'kmlPolyCoords' || $type == 'gmlKmlPolyCoords')) {
                $coords[] = $value;
            } elseif ($type == 'iso19139dcmiBox') {
                $tok = strtok($value, ";");
                $north = null;
                $south = null;
                $west = null;
                $east = null;
                while ($tok !== false) {
                    $keyValue = explode("=", $tok);
                    if (strtolower(trim($keyValue[0])) == 'northlimit' && is_numeric($keyValue[1])) {
                        $north = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'southlimit' && is_numeric($keyValue[1])) {
                        $south = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'westlimit' && is_numeric($keyValue[1])) {
                        $west = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'eastlimit' && is_numeric($keyValue[1])) {
                        $east = floatval($keyValue[1]);
                    }
                    $tok = strtok(";");<commit_msg>zero space trim for spatial type<commit_after><?php if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class Spatial_Extension extends ExtensionBase
{

    function __construct($ro_pointer)
    {
        parent::__construct($ro_pointer);
    }

    function determineSpatialExtents()
    {
        $extents = array();

        $sxml = $this->ro->getSimpleXML();
        $sxml->registerXPathNamespace("ro", RIFCS_NAMESPACE);
        $spatial_elts = $sxml->xpath('//ro:spatial');

        foreach ($spatial_elts AS $spatial) {
            $north = null;
            $south = null;
            $west = null;
            $east = null;
            $type = $spatial["type"];
            $value = preg_replace('!\s+!', ' ', (string)$spatial);
            if ($type == 'kmlPolyCoords' || $type == 'gmlKmlPolyCoords') {
                if ($this->isValidKmlPolyCoords($value)) {
                    $north = -90;
                    $south = 90;
                    $west = 180;
                    $east = -180;
                    $tok = strtok($value, " ");
                    while ($tok !== false) {
                        $keyValue = explode(",", $tok);
                        //$msg = $msg.'<br/>lat ' .$keyValue[1]. ' long '.$keyValue[0];
                        if (is_numeric($keyValue[1]) && is_numeric($keyValue[0])) {

                            $lng = floatval($keyValue[0]);
                            $lat = floatval($keyValue[1]);
                            //$msg = $msg.'<br/>lat ' .$lat. ' long '.$lng;
                            if ($lat > $north) {
                                $north = $lat;
                            }
                            if ($lat < $south) {
                                $south = $lat;
                            }
                            if ($lng < $west) {
                                $west = $lng;
                            }
                            if ($lng > $east) {
                                $east = $lng;
                            }
                        }
                        $tok = strtok(" ");
                    }

                }
            } elseif ($type == 'iso19139dcmiBox') {
                //northlimit=-23.02; southlimit=-25.98; westlimit=166.03; eastLimit=176.1; projection=WGS84
                $north = null;
                $south = null;
                $west = null;
                $east = null;
                $tok = strtok($value, ";");
                while ($tok !== false) {
                    $keyValue = explode("=", $tok);
                    if (strtolower(trim($keyValue[0])) == 'northlimit' && is_numeric($keyValue[1])) {
                        $north = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'southlimit' && is_numeric($keyValue[1])) {
                        $south = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'westlimit' && is_numeric($keyValue[1])) {
                        $west = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'eastlimit' && is_numeric($keyValue[1])) {
                        $east = floatval($keyValue[1]);
                    }
                    $tok = strtok(";");
                }
            } elseif ($type == 'iso19139dcmiPoint' || $type == 'dcmiPoint') //"name=<NAME>, AU; east=160.0; north=-40.0"
            {
                //northlimit=-23.02; southlimit=-25.98; westlimit=166.03; eastLimit=176.1; projection=WGS84
                $north = null;
                $south = null;
                $west = null;
                $east = null;
                $tok = strtok($value, ";");
                while ($tok !== false) {
                    $keyValue = explode("=", $tok);
                    if (strtolower(trim($keyValue[0])) == 'north' && is_numeric($keyValue[1])) {
                        $north = floatval($keyValue[1]);
                        $south = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'east' && is_numeric($keyValue[1])) {
                        $west = floatval($keyValue[1]);
                        $east = floatval($keyValue[1]);
                    }
                    $tok = strtok(";");
                }
            } elseif ($type == 'iso31661' || $type == 'iso31662' || $type == 'iso3166') //"name=<NAME>, AU; east=160.0; north=-40.0"
            {

                $north = null;
                $south = null;
                $west = null;
                $east = null;

                $gCoords = $this->getExtentFromGoogle(trim($value), $type);

                if ($gCoords) {
                    $north = floatval($gCoords['north']);
                    $south = floatval($gCoords['south']);
                    $west = floatval($gCoords['west']);
                    $east = floatval($gCoords['east']);
                }
            }
            //$msg = $msg.'<br/> north:'.$north.' south:'.$south.' west:'.$west.' east:'.$east;
            if ($this->isValidWSEN($west, $south, $east, $north)) {
                $extents[] = $west . " " . $south . " " . $east . " " . $north;
            }

        }
        return $extents;
    }

    function getLocationAsLonLats()
    {
        $coords = array();

        $sxml = $this->ro->getSimpleXML();
        $sxml->registerXPathNamespace("ro", RIFCS_NAMESPACE);
        $spatial_elts = $sxml->xpath('//ro:spatial');

        foreach ($spatial_elts AS $spatial) {

            $type = (string)trim($spatial["type"], $mask = " \t\n\r\0\x0B\xE2\x80\x8B");
            $value = preg_replace('!\s+!', ' ', (string)$spatial);

            if ($this->isValidKmlPolyCoords($value) && ($type == 'kmlPolyCoords' || $type == 'gmlKmlPolyCoords')) {
                $coords[] = $value;
            } elseif ($type == 'iso19139dcmiBox') {
                $tok = strtok($value, ";");
                $north = null;
                $south = null;
                $west = null;
                $east = null;
                while ($tok !== false) {
                    $keyValue = explode("=", $tok);
                    if (strtolower(trim($keyValue[0])) == 'northlimit' && is_numeric($keyValue[1])) {
                        $north = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'southlimit' && is_numeric($keyValue[1])) {
                        $south = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'westlimit' && is_numeric($keyValue[1])) {
                        $west = floatval($keyValue[1]);
                    }
                    if (strtolower(trim($keyValue[0])) == 'eastlimit' && is_numeric($keyValue[1])) {
                        $east = floatval($keyValue[1]);
                    }
                    $tok = strtok(";");
{'fraction_non_alphanumeric': 0.16433516008076146, 'fraction_numerical': 0.01903663109316412, 'mean_word_length': 1.217620722737448, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '2370324', 'n_tokens_mistral': 4200, 'n_tokens_neox': 3818, 'n_words': 652}