Ejemplo n.º 1
0
function InsertDlib2($content, $uri, $item, $ArtTitle)
{
    //http://www.dlib.org/dlib/january14/01contents.html
    $Work = $item;
    $Exp = $Work . "_ver1";
    $get = CreateResource($uri, $item, $Work, $Exp, $ArtTitle);
    if ($get != null) {
        return;
    }
    $content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");
    $doc = new DOMDocument();
    $doc->loadHTML($content);
    $xpath = new DOMXPath($doc);
    //Titolo dell'articolo
    $title = $doc->getElementsByTagName('h3')->item(1);
    if ($title != NULL) {
        CreateTitle($Exp, $item, $title->nodeValue, 0, strlen($title->nodeValue), $title->getAttribute('id'), $uri);
    }
    //Autori dell'articolo
    $audID = 'form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p2';
    $autArray = $xpath->query("//p[@id='{$audID}']/text()");
    $autStart = 0;
    function Authors($autori, $del_Len, $autStartTmp, $Exp, $item, $autStart, $audID, $uri)
    {
        foreach ($autori as $node) {
            if (is_array($node) && count($node) > 1) {
                $autStartTmp = Authors($node, 1, $autStartTmp, $Exp, $item, $autStart, $audID, $uri) + 5;
                continue;
            }
            if (is_array($node)) {
                $autStartTmp = Authors($node, 5, $autStartTmp, $Exp, $item, $autStart, $audID, $uri) + 5;
                continue;
            }
            $end = 0;
            $autStartTmp = $autStartTmp + (strlen($node) - strlen(ltrim($node)));
            $end = strlen($node) - strlen(rtrim($node));
            $node = trim($node);
            $node = Normalize($node);
            //print $node." ".$autStart.$autStartTmp."<br>";
            CreateAuthors($Exp, $item, $node, $autStart + $autStartTmp, $autStart + $autStartTmp + strlen($node), $audID, $uri);
            $autStartTmp = $autStartTmp + strlen($node) + $end + $del_Len;
        }
        return $autStartTmp - $del_Len;
    }
    for ($i = 0; $i < $autArray->length; $i++) {
        $aut = $autArray->item($i);
        if ($i != 0 && strlen($aut->nodeValue) - strlen(ltrim($aut->nodeValue)) != 2) {
            $autStart = $autStart + strlen($aut->nodeValue);
            continue;
        }
        if ($Work == "01kabore") {
            $node = $aut->nodeValue;
            $node = Normalize($node);
            $pos1 = strpos($node, " ");
            $pos2 = strpos($node, " ", $pos1 + 1);
            if ($i != 0) {
                $node = substr($node, 0, $pos2);
            } else {
                $pos3 = strpos($node, " ", $pos2 + 1);
                $node = substr($node, 0, $pos3);
            }
            $node = substr($node, 0, strlen($node) - 1);
            CreateAuthors($Exp, $item, $node, $autStart, $autStart + strlen($node), $audID, $uri);
        } else {
            $aut = MultiDelimiter(array(" and ", ","), $aut->nodeValue);
            Authors($aut, 5, 0, $Exp, $item, $autStart, $audID, $uri);
        }
        $autStart = $autStart + strlen($autArray->item($i)->nodeValue);
        $i++;
        $autStart = $autStart + strlen($autArray->item($i)->nodeValue);
    }
    //Abstract
    $astratto = $xpath->query("//h3[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_h33']/following-sibling::p[1]")->item(0);
    if ($astratto != null) {
        CreateRethoric($Exp, $item, "sro:Abstract", "Questo è l' astratto dell'articolo.", 0, strlen($astratto->nodeValue), $astratto->getAttribute('id'), $uri);
    }
    /*
    //Introduction
    $intro=$xpath->query("//h3[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_h34']")->item(0);
    if(($intro->nodeValue.localeCompare("Introduction"))==0){	
    	$introduzione=$xpath->query("//h3[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_h34']/following-sibling::p[1]")->item(0);
    	if($introduzione!= null)
    		CreateRethoric($Exp, $item, "deo:Introduction", "Questa è l' introduzione dell'articolo.", 0, strlen($introduzione->nodeValue), $introduzione->getAttribute('id'), $uri);
    }
    */
    //URL
    $url = $xpath->query("//a[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p3_a1']")->item(0);
    if ($url != null) {
        CreateUrl($Exp, $item, Normalize($url->nodeValue), 0, strlen(Normalize($url->nodeValue)), $url->getAttribute('id'), $uri, "Questo testo rappresenta l' indirizzo:" . $url->getAttribute('href'));
    }
    $url = $xpath->query("//a[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p1_a1']")->item(0);
    if ($url != null) {
        CreateUrl($Exp, $item, Normalize($url->nodeValue), 0, strlen(Normalize($url->nodeValue)), $url->getAttribute('id'), $uri, "Questo testo rappresenta l' indirizzo:" . $url->getAttribute('href'));
    }
    //Anno di pubblicazione dell'articolo
    $target = $xpath->query("//p[1]")->item(0);
    $AllStr = $xpath->query("//p[1]//text()[(following::br)]")->item(0);
    $publicationYear = substr($AllStr->nodeValue, -4);
    CreatePublicationYear($Exp, $item, $publicationYear, strlen($AllStr->nodeValue) - 4, strlen($AllStr->nodeValue), $target->getAttribute('id'), $uri);
    //DOI dell'articolo
    $target = $xpath->query("//p[2]")->item(0);
    $target_text = Normalize($target->nodeValue);
    $aux = $xpath->query("//p[2]//text()[(preceding::br)]");
    $doi = Normalize(substr($aux->item($aux->length - 1)->nodeValue, 4));
    CreateDoi($Exp, $item, $doi, strpos($target_text, $doi), strpos($target_text, $doi) + strlen($doi), $target->getAttribute('id'), $uri);
    if ($Work == "01musgrave") {
        $cities1 = $xpath->query("//p[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p17']")->item(0);
        $i = 1;
        $citExp = $Exp . "_cited" . $i;
        $citazione = Normalize($cities1->nodeValue);
        //autori
        $pos_punto = strpos($citazione, '.');
        $autori = substr($citazione, 0, $pos_punto);
        $arr_aut = explode('&', $autori);
        $start = 0;
        foreach ($arr_aut as $node) {
            if (strpos($node, ',')) {
                $var = str_replace(',', ' ', $node);
                $var = trim($var);
            } else {
                $var = trim($node);
            }
            CreateAuthors($citExp, $item, $var, $start, $start + strlen($var), $cite->getAttribute('id'), $uri);
            $start += strlen($var) + 2;
        }
        //anno
        $anno = substr($citazione, $pos_punto, 5);
        CreatePublicationYear($Exp, $item, $anno, $pos_punto + 1, $pos_punto + 5, $target->getAttribute('id'), $uri);
    }
    /*//Work = Nome Senza Estensione
    //Exp = Nome Con _ver1
    $Work = $item;
    $Exp = $Work."_ver1";
    
    $get = CreateResource($uri, $item, $Work, $Exp, $ArtTitle);
    if($get != null) return;
    $content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");
    $doc = new DOMDocument();	
    $doc->loadHTML($content);
    $xpath = new DOMXPath($doc);
    
    //Titolo dell'articolo
    $title = $doc->getElementsByTagName('h3')->item(0);
    if($title != NULL){
    	 CreateTitle($Exp, $item, $title->nodeValue, 0, strlen($title->nodeValue), $title->getAttribute('id'), $uri);
    }
    
    //Autori articolo
    $aut= $xpath->query("//p[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p2']/text()[(following::br)]")->item(0);
    $str=str_replace(" and ", ",", $aut->nodeValue);
    $arr = explode(",", $str);
    $start=0;
    foreach($arr as $node){
    	$var = trim($node);
    	$start=strpos($aut->nodeValue, $var); //posizione dell'autore in tutta la frase compreso "and"
    	$end=$start+strlen($var);
    	CreateAuthors($Exp, $item, $var, $start,($end-1), $autTarget, $uri);
    }
    
    //Anno di pubblicazione dell'articolo
    $target=$xpath->query("//p[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p1']")->item(0);
    $ab = $xpath->query("//p[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p1']/text()[(following::br)]")->item(0);
    $publicationYear = substr($ab->nodeValue, -4, 4);
     CreatePublicationYear($Exp, $item, $publicationYear, strlen($ab->nodeValue) - 4, strlen($ab->nodeValue)+1, $target->getAttribute('id'), $uri); 
    
    
    //DOI dell'articolo
    $target=$xpath->query("//p[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p2']")->item(0);
    $ab = $xpath->query("//p[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p2']/text()[(preceding::br)]");
    foreach($ab as $node){ //scorre all'ultimo br dato che il DOI è sempre dopo l'ultimo br
    $ab=$node;
    }
    $doi=$ab->nodeValue;
    $start=strpos($target->nodeValue,$doi);
     CreateDoi($Exp, $item, $doi, $start, strlen($doi), $target->getAttribute('id'), $uri);
    
    
    //Abstract
    $astratto = $xpath->query("//h3[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_h33']/following-sibling::p[1]")->item(0);
    CreateRethoric($Exp, $item, "sro:Abstract", "Questo è l' astratto dell'articolo.", 0, strlen($astratto->nodeValue), $astratto->getAttribute('id'), $uri);
    
    //URL
    $url = $xpath->query("//a[@id='form1_table3_tr1_td1_table5_tr1_td1_table1_tr1_td2_p3_a1']")->item(0);
    CreateUrl($Exp, $item, Normalize($url->nodeValue), 0, strlen(Normalize($url->nodeValue)), $url->getAttribute('id'), $uri, "Questo testo rappresenta l' indirizzo:".$url->getAttribute('href'));
    
    
    //Citazioni dell'articolo
    $target = $xpath->query("//*[(preceding::h3[text()=\"References\"||text()=\"Notes\"])]");
    $i=0;
    foreach($target as $node){
    	$citExp=$Exp."_cited".$i;
    	if($node->nodeName!='p')
    		break;
    	else{
    		$pos=strpos($node->nodeValue,'"');
    		$t=substr($node->nodeValue, $pos);
    		$pos=strpos($t,'"');
    		//$title=substr($t, $pos);
    		CreateCities($t, $citExp, $Exp, $item, $node->nodeValue, $node->getAttribute('id'), 0, strlen($cite->nodeValue), $uri);
    		
    	}
    	
    }
    */
}
Ejemplo n.º 2
0
<?php

require_once "../vendor/autoload.php";
function UpdateEndPoint()
{
    //return "http://*****:*****@ltw1516.it>\n        a                          <http://xmlns.com/foaf/0.1/Person> ;\n        <http://schema.org/email>  '*****@*****.**' ;\n        <http://www.w3.org/2006/vcard/ns#hasKey>\n                '21232f297a57a5a743894a0e4a801fc3' ;\n        <http://xmlns.com/foaf/0.1/name>\n                'admin' ;\n        <http://xmlns.com/foaf/0.1/openid>\n                'admin' .\n\n\t\t\t\t}\n\t}";
    $delete = "\n\tINSERT DATA{\n\t" . Insert . "\n\t\t\t\t{\n\t\t\t\t  <mailto:admin@ltw1516.it>\n        a                          <http://xmlns.com/foaf/0.1/Person> ;\n        <http://schema.org/email>  '*****@*****.**' ;\n        <http://www.w3.org/2006/vcard/ns#hasKey>\n                '21232f297a57a5a743894a0e4a801fc3' ;\n        <http://xmlns.com/foaf/0.1/name>\n                'admin' ;\n        <http://xmlns.com/foaf/0.1/openid>\n                '*****@*****.**' .\n\n\t\t\t\t}\n\t}";
    $answer = Update($delete);
    $answer = Update($Query);
    return $answer;
}
CreateResource();