print all triples into RDF files - php

i'm using rdfapi-php library and trying to open my RDF file.
Here are the code edited from the tutorial to show the content parsed into the way the library explain.
//include RDF API
define("RDFAPI_INCLUDE_DIR", "C:/OpenSA/Apache/htdocs/rdf_api/api/");
include(RDFAPI_INCLUDE_DIR . "RDFAPI.php");
// Filename of an RDF document
$base="example1.rdf";
// Create a new MemModel
$model = ModelFactory::getDefaultModel();
// Load and parse document
$model->load($base);
// Get Iterator from model
$it = $model->getStatementIterator();
// Traverse model and output statements
while ($it->hasNext()) {
$statement = $it->next();
echo "Statement number: " . $it->getCurrentPosition() . "<BR>";
echo "Subject: " . $statement->getLabelSubject() . "<BR>";
echo "Predicate: " . $statement->getLabelPredicate() . "<BR>";
echo "Object: " . $statement->getLabelObject() . "<P>";
}
that is the output
Statement number: 0
Subject: http://www.w3.org/Home/Lassila
Predicate: http://description.org/schema/Creator
Object: e85740
Statement number: 1
Subject: e85740
Predicate: http://www.w3.org/1999/02/22-rdf-syntax-ns#type
Object: http://description.org/schema/Person
My problem is that in the variable $base i will have an array with the name of all my RDF files. How i can edit the script to get the content of all the file of the array and after that print every RDF triple?
Regards

Related

Searching for file in directory using glob, not returning results

I'm trying to make a small script for retrieving configuration files containing mapping instructions for a product import, using php glob. But I fail miserably.
What I have right now:
echo "Shop type: " . $this->shopType . '<br />';
echo "Shop version: " . $this->shopVersion . '<br />';
echo "Glob search: config/mappings/" . $this->shopType . "_" . $this->shopVersion . ".php";
foreach (glob("config/mappings/" . $this->shopType . "_" . $this->shopVersion . ".php") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
exit;
$this->shopType represents the name of the shop from which the export file should be imported. E.g. ccvshop.
$this->shopVersion represents the version of the shop, to be able to write different import mappings for different versions of the shop types.
The value of shopType = ccvshop.
The value of shopVersion = 11.2.
Which would make the search string in the glob function:
config/mappings/ccvshop_11.2.php.
Unfortunately my result is empty, and I can't see what I'm doing wrong.
Any help would be appreciated.
I added an image representing my directory structure:
glob() returns an array of matching files. It looks like you already know the name of the file that you want to read. Try something like this:
$filename = "config/mappings/" . $this->shopType . "_" . $this->shopVersion . ".php";
if (file_exists($filename))
echo "$filename:" . filesize($filename);

PHP: sort ZIP in alphabetical order

The following PHP file creates a ZIP File and works as it should.
<?php
$zip = new ZipArchive();
$ZIP_name = "./path/Prefix_" .$date . ".zip";
if ($zip->open($ZIP_name, ZipArchive::CREATE)!==TRUE) {
exit("There is a ZIP Error");
}
if ($zip->open($ZIP_name, ZipArchive::CREATE)==TRUE) {
echo "ZIP File can be created" . "<br>";
}
foreach($list as $element) {
$path_and_filename = "../path_to_somewhere/product_"
. $element
. ".csv";
$zip->addFile($path_and_filename, basename($path_and_filename));
}
echo "numfiles: " . $zip->numFiles . "\n"; // number of element files
echo "status:" . $zip->status . "\n"; // Status "0" = okay
$zip->close();
?>
There is only a small blemish:
The above foreach-loop retrieves elements from an array where all elements are sorted in alphabetical order. After the ZIP-File creation, the files within the ZIP are in different order, maybe caused by different file size.
Is there a way to sort the csv files within the ZIP with PHP later on? I'm new to ZIP creation with PHP an I have not found something helpful in the documentation.
You can't do that, better just sort the file list in your program, not in the file system (-;

google-api-php-client - Get File Contents

Using the following code:
// get the file contents
$file = new Google_Service_Drive_DriveFile();
$fileId = 'The File ID';
try {
echo 'try part <br>';
$result3 = $service->files->get($fileId);
echo 'Contents: ' . $result3->getContent().'<br>';
echo "Title: " . $result3->getTitle() . '<br>';
echo "Description: " . $result3->getDescription() . '<br>';
echo "MIME type: " . $result3->getMimeType() . '<br>';
} catch (Exception $e) {
echo "An error occurred: " . $e->getMessage();
};
Everything works except for this line:
echo 'Contents: ' . $result3->getContent().'<br>';
In the drive.php file in the API, there is a getContent() function, but it's not working. How do I get the content out of the file?
If you refer to the Google documentation at https://developers.google.com/drive/v2/reference/files/get you'll see that there are two forms of the Get method. The default fetches the metadata (eg. title, description, etc), whereas alt=media fetches the content. Alternatively, you can also fetch the content via the downloadUrl property. I don't know if the PHP library exposes the alt=media option (I don't like libraries), but the downloadUrl approach has an example on the page I linked, just scroll down and click "php"

Not getting desire output

What I want to do is,
I am initializing $message variable for mail body.
And I has to iterate through loop if multiple files are there.
So how can i iterate loop and store values in a variable.
Like,
$message = "Dear " . $fname . " <br/>
<b>Manuscript and Other Documents :</b> <br/>
Source File : " .$file1 . " <br/>
Source PDF File : ".$file2 . " <br/>
Cover Letter : " . $file3 . "<br/>
Supplementary Files : " . while($row=mysql_fetch_array($supplementary)){ echo $row[0] } . ";
So how can i do this if i have multiple supplementary files?
To do this, simply append the data to the message variable within the while loop using the string concatenation operator.
For example:
$message = "Dear " . $fname . " <br/><b>Manuscript and Other Documents :</b><br/>
Source File : " .$file1 . "<br/>Source PDF File : ".$file2 . " <br/>
Cover Letter : " . $file3 . "<br/>Supplementary Files : ";
while($row = mysql_fetch_array($supplementary)) {
$message .= echo $row[0] . '<br />';
}
First, do this:
$suplArray = array();
while($row=mysql_fetch_array($supplementary)){
$suplArray[] = $row[0];
}
Now, you have the strings in an array. I don't know what format you want, but you can do something like
$suplStr = implode(',', $suplArray);
Then in your string, you can have:
... "Supplementary Files : " . $suplStr;

Generate XML with 'SimpleXMLElement' with some empty filelds?

$sitemap .= " " . '<orders>' . "\n" .
"\t" . '<idKlant>' . $id. '</idKlant>' .
"\n\t" . '<emptyfield></emptyfield>' .
"\n\t" . '<date>' . $verzenddatum . '</date>' . //remaining to get
"\n " . '</orders>' . "\n";
For generating XMl, I am using below code
$xmlobj = new SimpleXMLElement($sitemap);
$xmlobj->asXML("orders.xml");
Output of orders.xml
<orders>
<idKlant>12</idKlant>
<emptyfield/>
<date>30-12-2012</date>
</orders>
What i want is: for Empty xml field there should be Opening and Closing tag as well
<orders>
<idKlant>12</idKlant>
<emptyfield></emptyfield>
<date>30-12-2012</date>
</orders>
Is it possible? OR should i add black space?
As Rolando Isidoro said you can't do it with SimpleXML. But you can always switch to the DOM. Both extension use the same underlying library and representation, so there is very little overhead.
DOMDocument::saveXML can take libxml options as the second parameter and there is LIBXML_NOEMPTYTAG which does exactly what you want.
e.g.
<?php
$o = new SimpleXMLELement(data());
$docRoot = dom_import_simplexml($o);
echo $docRoot->ownerDocument->savexml($docRoot,LIBXML_NOEMPTYTAG);
function data() {
return '<orders>
<idKlant>12</idKlant>
<emptyfield/>
<date>30-12-2012</date>
</orders>';
}
prints
<orders>
<idKlant>12</idKlant>
<emptyfield></emptyfield>
<date>30-12-2012</date>
</orders>

Categories