예제 #1
0
}
$restClient = new MLPHP\RESTClient($mlphp['host'], $mlphp['port'], $mlphp['path'], $mlphp['version'], $mlphp['username'], $mlphp['password'], $mlphp['auth']);
$rootdir = 'bills';
$subdirs = array('110', '111', '112');
// directories to import from
// Loop through files from subdirectories
foreach ($subdirs as $subdir) {
    $count = 0;
    $dir = $rootdir . '/' . $subdir;
    if ($handle = opendir($dir)) {
        //echo "Writing files from directory: " . $dir . "<br />";
        $doc = new MLPHP\Document($restClient);
        while (false !== ($file = readdir($handle))) {
            if (substr($file, 0, 1) !== ".") {
                $doc->setContentType("application/xml");
                $content = $doc->setContentFile($dir . '/' . $file)->getContent();
                $uri = '/bills/' . $subdir . '/' . $file;
                // URI example: '/bills/112/h321.xml'
                $dom = new DOMDocument();
                $dom->loadXML($content);
                // Only write bills with related bills and short titles
                $num_rel_bills = $dom->getElementsByTagName('relatedbill')->length;
                $len_title = strlen($dom->getElementsByTagName('title')->item(0)->nodeValue);
                if ($num_rel_bills == 0 || $len_title > 80) {
                    continue;
                }
                $xpath = new DOMXPath($dom);
                // Set collection base on bill type. Example: 'hr' (House resolution)
                $type = $xpath->query('//bill/@type')->item(0)->nodeValue;
                $params = array("collection" => $type);
                $count++;
예제 #2
0
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Example: Connect to ML with a REST client</title>
</head>

<?php 
// Set up global vars and class autoloading
require_once 'setup.php';
$client = $mlphp->newClient();
$client->setUsername($mlphp->config['username-admin']);
$client->setPassword($mlphp->config['password-admin']);
// Write a doc via PUT
$doc = new MLPHP\Document($client);
$file = 'example.xml';
$doc->setContentFile($file);
$uri = "/" . $file;
echo '<br />Write: ' . $doc->write($uri)->getUri() . '<br />' . PHP_EOL;
// Read a doc via GET
echo '<br />Read: ' . $doc->read($uri) . '<br />' . PHP_EOL;
// Delete a doc via DELETE
echo '<br />Delete: ' . $doc->delete($uri)->getUri() . '<br />' . PHP_EOL;
// Test 301 redirect
$govTrackClient = new MLPHP\RESTClient('www.govtrack.us', 0, 'api', 'v1');
// Get Senate bills from bill endpoint
$params = array('bill_type' => 'senate_bill');
// 'bill' resource results in redirect ('bill/' does not)
$request = new MLPHP\RESTRequest('GET', 'bill', $params);
$response = $govTrackClient->send($request);
//print_r($response->getBody());
echo '<br />Title of second bill object: <br />';
예제 #3
0
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
use MarkLogic\MLPHP;
?>
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Example: Chaining Document Methods</title>
</head>

<?php 
// Set up global vars and class autoloading
require_once 'setup.php';
$client = $mlphp->newClient();
$client->setUsername($mlphp->config['username-admin']);
$client->setPassword($mlphp->config['password-admin']);
// Write text as a document to the database
$doc = new MLPHP\Document($client);
echo $doc->setContent('Hello, PHP!')->write('/chained1.txt')->getContent();
echo '<br />';
echo $doc->setContentFile('example.xml')->write('/chained2.xml')->getContent();
echo '<br />';
$doc2 = new MLPHP\Document($client);
echo $doc2->write();
?>

</body>
</html>
예제 #4
0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Setup
use MarkLogic\MLPHP;
require_once 'setup.php';
$client = $mlphp->newClient();
$client->setUsername($mlphp->config['username-admin']);
$client->setPassword($mlphp->config['password-admin']);
// Load some documents
$doc = new MLPHP\Document($client);
$doc->setContentFile("hamlet.xml")->write("/" . "hamlet.xml");
$doc->setContentFile("macbeth.xml")->write("/" . "macbeth.xml");
$doc->setContentFile("example.json")->write("/" . "example.json");
// Search for a string
$search = new MLPHP\Search($client);
$search->setPageLength(2);
$results = $search->retrieve('donalbain');
echo "Simple text search results:\n\n";
print_r($results);
echo "\n\n\n";
// Search by key-value for an element
$search->setPageLength(1);
$results = $search->retrieveKeyValueElement('PLAYSUBT', '', 'HAMLET');
echo "Key-value (for an element) search results:\n\n";
print_r($results);
echo "\n\n\n";
예제 #5
0
 public static function loadDocsJSON($client)
 {
     // Load json files
     $dir = __DIR__ . DIRECTORY_SEPARATOR . 'docs' . DIRECTORY_SEPARATOR . 'nv';
     $count = 0;
     if ($handle = opendir($dir)) {
         parent::$logger->debug("Writing files from directory: " . $dir);
         $doc = new MLPHP\Document($client);
         while (false !== ($file = readdir($handle))) {
             if (substr($file, 0, 1) !== ".") {
                 $doc->setContentType("application/json");
                 $content = $doc->setContentFile($dir . '/' . $file)->getContent();
                 $uri = '/legislators/' . $file;
                 // URI example: '/legislators/Care.json'
                 $obj = json_decode($content);
                 $params = array("collection" => $obj->{'old_roles'}->{'2009-2010'}[0]->party);
                 $count++;
                 parent::$logger->debug($count . ': ' . $uri);
                 // Write content to database via REST client
                 $doc->write($uri, $params);
             }
         }
         closedir($handle);
     }
     parent::$logger->debug('JSON files loaded: ' . $count);
 }
예제 #6
0
// Files from a directory
$dir = __DIR__ . '/several';
// Get directory relative to current directory
$doc6 = new MLPHP\Document($client);
// Create a Document object (passing the REST client)
if ($handle = opendir($dir)) {
    // Create a directory handle for reading
    echo 'Reading files from directory: ' . $dir . "\n\n";
    $files = array();
    while (false !== ($file = readdir($handle))) {
        // Read each file in the directory
        if (substr($file, 0, 1) !== '.') {
            // Ignore special files
            $files[] = $file;
            // Store the file URIs in an array
            $doc6->setContentFile($dir . '/' . $file);
            // Set the file as the document content
            $doc6->setContentType('application/xml');
            // Set the content type for the document
            $uri6 = '/' . $file;
            // Define the URI for the document
            $doc6->write($uri6);
            // Write the document to the database
        }
    }
    closedir($handle);
}
// Read the documents from the database
echo "Read the documents:\n";
foreach ($files as $i => $file) {
    // Loop through the file URIs
예제 #7
0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Setup
use MarkLogic\MLPHP;
require_once 'setup.php';
$client = $mlphp->newClient();
$client->setUsername($mlphp->config['username-admin']);
$client->setPassword($mlphp->config['password-admin']);
// Write a sample document
$doc1 = new MLPHP\Document($client);
$file1 = 'example.xml';
$doc1->setContentFile($file1);
$doc1->setContentType('application/xml');
$uri1 = '/' . $file1;
$doc1->write($uri1);
// Reset metadata to default by deleting
$doc1->deleteMetadata();
// Delete the metadata for the document
$meta1 = $doc1->readMetadata();
// Read the metadata for the document
echo "Starting collections:\n";
print_r($meta1->getCollections());
// Read and display the collections metadata for the document
echo "Starting properties:\n";
print_r($meta1->getProperties());
// Read and display the properties metadata for the document
echo "Starting permissions:\n";