<commit_before><?php
function authenticateUser() {
	$app = \Slim\Slim::getInstance();
	if(empty($_SESSION['user'])){
		$app->flash('error', 'ログインが必要な領域です。');
		$app->redirect($app->config('static_path') . 'login');
	}else if($_SESSION['expires'] < time()){
		session_destroy();
		session_regenerate_id(true);
		session_start();
		$app->flash('error', 'ログインの有効期限が切れました');
		$app->redirect($app->config('static_path') . 'login');
	}else{
		$_SESSION['expires'] = time() + (int)$app->config('timeout');
	}
};

function checkToken($post, $app){
	if(empty($post['_token']) || session_id() !== $post['_token']){
		$app->flash('error', '何か不正なフローがありました。もう一度始めからお試し下さい。');
		$app->redirect($app->config('static_path') . '');
	}
}

function downloadZip($format = null){

	$app = \Slim\Slim::getInstance();
	$extension = array(
		'xml' => 'xml',
		'rdfxml' => 'xml',
		'jsonld' => 'json',
		'turtle' => 'ttl',
		'ntriples' => 'nt'
	);
	if(!array_key_exists($format, $extension)){
		$app->flash('error', '指定された出力形式が不正です。');
		throw new RuntimeException('指定された出力形式が不正です。');
	}

	$zip = new ZipArchive();
	$zipFileName = 'data.zip';
	$zipFilePath = $app->config( 'uploadPath' ) ;

	$check = $zip->open($zipFilePath.$zipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
	if ($check !== true) {
		$app->flash('error', 'zipファイルの作成に失敗しました');
		throw new RuntimeException('zipファイルの作成に失敗しました');
	}

	if($format == 'xml'){
		$zip->addFromString('dataSchema.xsd' , getSchema());
		$xml = new XMLConverter();
		$output = $xml->getXML();
	}else{
		$rdf = new RDFConverter();
		$rdf->parseGraph($format);
		$output = $rdf->output();
	}
	$zip->addFromString('convertedData.'  . $extension[$format] , $output);
	$zip->addFromString('dataTemplate.xml' , getTemplateXML());
	$zip->addFromString('mapping.json' , getMapping());

	$zip->close();

	$app->response->headers->set( 'Content-Type', 'application/zip; name="' . $zipFileName . '"' );
	$app->response->headers->set( 'Content-Disposition', 'attachment; filename="' . $zipFileName . '"' );
	$app->response->headers->set( 'Content-Length', filesize($zipFilePath.$zipFileName) );
	$app->response->write( file_get_contents($zipFilePath.$zipFileName));

	unlink($zipFilePath.$zipFileName);
}

//------------------------------------------------------------------------------------
// ic関連
//------------------------------------------------------------------------------------
function getChildElementByComplexTypeName($complexTypeName, $vocabulary, $prefix){
	$app = \Slim\Slim::getInstance();

	$filePath = $app->config('schemaPath') . $vocabulary . '.' . $prefix['extension'];
	$xml       = file_get_contents( $filePath );
	$xmlObject = simplexml_load_string( $xml );
	$namespace = 'xsd';
	if($vocabulary == 'xsd'){
		$namespace = 'xs';
	}
	$children  = $xmlObject->children( $namespace, true );
	$propertyElements = $children->element;
	$temp = array();
	$temp['element'] = array();
	foreach ( $children->complexType as $value ) {
		if ( (string) $value->attributes()->name != $complexTypeName ) {
			continue;
		}
		$temp['name'] = (string) $value->attributes()->name;
		if(isset($value->complexContent->extension)){
			$extensionName = $value->complexContent->extension->attributes()->base;
			$extensionChildElements = getChildElementByComplexTypeName(str_replace($vocabulary . ":", "", $extensionName), $vocabulary, $prefix);
			if(!empty($extensionChildElements['element'])){
				$temp['element'] = array_merge($temp['element'],$extensionChildElements['element']);
			}
		}
		if ( ! empty( $value->complexContent ) ) {
			foreach ( (object) $value->complexContent->extension->sequence->element as $element ) {
				$ref                       = (string) $element->attributes()->ref;
				$type = null;
				foreach ( $propertyElements as $propertyElement ) {
					$name = str_replace($vocabulary . ":", '', $ref);
					if((string) $propertyElement->attributes()->name == $name){
						$type = (string) $propertyElement->attributes()->type;
						break;
					}
				}
				$temp['element'][] = array(
					'name' => $ref,
					'type' => $type
				);
			}
		} elseif ( ! empty( $value->simpleContent ) ) {
			foreach ( (object) $value->simpleContent->extension->attribute as $attribute ) {
				$type                      = (string) $attribute->attributes()->type;
				$temp['element'][] = $type;
			}
		}<commit_msg>For IMI ver2.3.1<commit_after><?php
function authenticateUser() {
	$app = \Slim\Slim::getInstance();
	if(empty($_SESSION['user'])){
		$app->flash('error', 'ログインが必要な領域です。');
		$app->redirect($app->config('static_path') . 'login');
	}else if($_SESSION['expires'] < time()){
		session_destroy();
		session_regenerate_id(true);
		session_start();
		$app->flash('error', 'ログインの有効期限が切れました');
		$app->redirect($app->config('static_path') . 'login');
	}else{
		$_SESSION['expires'] = time() + (int)$app->config('timeout');
	}
};

function checkToken($post, $app){
	if(empty($post['_token']) || session_id() !== $post['_token']){
		$app->flash('error', '何か不正なフローがありました。もう一度始めからお試し下さい。');
		$app->redirect($app->config('static_path') . '');
	}
}

function downloadZip($format = null){

	$app = \Slim\Slim::getInstance();
	$extension = array(
		'xml' => 'xml',
		'rdfxml' => 'xml',
		'jsonld' => 'json',
		'turtle' => 'ttl',
		'ntriples' => 'nt'
	);
	if(!array_key_exists($format, $extension)){
		$app->flash('error', '指定された出力形式が不正です。');
		throw new RuntimeException('指定された出力形式が不正です。');
	}

	$zip = new ZipArchive();
	$zipFileName = 'data.zip';
	$zipFilePath = $app->config( 'uploadPath' ) ;

	$check = $zip->open($zipFilePath.$zipFileName, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
	if ($check !== true) {
		$app->flash('error', 'zipファイルの作成に失敗しました');
		throw new RuntimeException('zipファイルの作成に失敗しました');
	}

	if($format == 'xml'){
		$zip->addFromString('dataSchema.xsd' , getSchema());
		$xml = new XMLConverter();
		$output = $xml->getXML();
	}else{
		$rdf = new RDFConverter();
		$rdf->parseGraph($format);
		$output = $rdf->output();
	}
	$zip->addFromString('convertedData.'  . $extension[$format] , $output);
	$zip->addFromString('dataTemplate.xml' , getTemplateXML());
	$zip->addFromString('mapping.json' , getMapping());

	$zip->close();

	$app->response->headers->set( 'Content-Type', 'application/zip; name="' . $zipFileName . '"' );
	$app->response->headers->set( 'Content-Disposition', 'attachment; filename="' . $zipFileName . '"' );
	$app->response->headers->set( 'Content-Length', filesize($zipFilePath.$zipFileName) );
	$app->response->write( file_get_contents($zipFilePath.$zipFileName));

	unlink($zipFilePath.$zipFileName);
}

//------------------------------------------------------------------------------------
// ic関連
//------------------------------------------------------------------------------------
function getChildElementByComplexTypeName($complexTypeName, $vocabulary, $prefix){
	$app = \Slim\Slim::getInstance();

	$filePath = $app->config('schemaPath') . $vocabulary . '.' . $prefix['extension'];
	$xml       = file_get_contents( $filePath );
	$xmlObject = simplexml_load_string( $xml );
	$namespace = 'xsd';
	if($vocabulary == 'xsd'){
		$namespace = 'xs';
	}
	$children  = $xmlObject->children( $namespace, true );
	$propertyElements = $children->element;
	$temp = array();
	$temp['element'] = array();
	foreach ( $children->complexType as $value ) {
		if ( (string) $value->attributes()->name != $complexTypeName ) {
			continue;
		}
		$temp['name'] = (string) $value->attributes()->name;
		if(isset($value->complexContent->extension)){
			$extensionName = $value->complexContent->extension->attributes()->base;
			$extensionChildElements = getChildElementByComplexTypeName(str_replace($vocabulary . ":", "", $extensionName), $vocabulary, $prefix);
			if(!empty($extensionChildElements['element'])){
				$temp['element'] = array_merge($temp['element'],$extensionChildElements['element']);
			}
		}
		if ( ! empty( $value->complexContent ) && isset($value->complexContent->extension->sequence->group)) {
			$groupRef = str_replace('ic:', '', $value->complexContent->extension->sequence->group->attributes()->ref);
			$elements = null;
			foreach ( $children->group as $group ) {
				if ( (string) $group->attributes()->name === $groupRef ) {
					$elements = $group->sequence->element;
					break;
				}
			}
			if(is_object($elements)){
				foreach ( (object) $elements as $element ) {
					$ref                       = (string) $element->attributes()->ref;
					$type = null;
					foreach ( $propertyElements as $propertyElement ) {
						$name = str_replace($vocabulary . ":", '', $ref);
						if((string) $propertyElement->attributes()->name == $name){
							$type = (string) $propertyElement->attributes()->type;
							break;
						}
					}
					if(strpos($type, '単純型')){
						foreach ( $children->simpleType as $simpleType ) {
							if ( (string) $simpleType->attributes()->name === str_replace('ic:', '', $type) ) {
								$type = (string) $simpleType->restriction->attributes()->base;
								break;
							}
						}
					}
					$temp['element'][] = array(
						'name' => $ref,
						'type' => $type
					);
				}
			}
		} elseif ( ! empty( $value->simpleContent ) ) {
			foreach ( (object) $value->simpleContent->extension->attribute as $attribute ) {
				$type                      = (string) $attribute->attributes()->type;
				$temp['element'][] = $type;
			}
		}
{'fraction_non_alphanumeric': 0.2440355194179951, 'fraction_numerical': 0.000320958596341072, 'mean_word_length': 3.735562310030395, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 162, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '574134', 'n_tokens_mistral': 3465, 'n_tokens_neox': 3090, 'n_words': 473}