示例#1
0
 /**
  * @param Document|Asset|Object_Abstract $element
  * @return array
  */
 public static function getDependencyForFrontend($element)
 {
     if ($element instanceof Document) {
         return array("id" => $element->getId(), "path" => $element->getFullPath(), "type" => "document", "subtype" => $element->getType());
     } else {
         if ($element instanceof Asset) {
             return array("id" => $element->getId(), "path" => $element->getFullPath(), "type" => "asset", "subtype" => $element->getType());
         } else {
             if ($element instanceof Object_Abstract) {
                 return array("id" => $element->getId(), "path" => $element->getFullPath(), "type" => "object", "subtype" => $element->geto_Type());
             }
         }
     }
 }
示例#2
0
 /**
  * @param  Document $target
  * @param  Document $source
  * @return Document copied document
  */
 public function copyRecursive($target, $source)
 {
     // avoid recursion
     if (!$this->_copyRecursiveIds) {
         $this->_copyRecursiveIds = array();
     }
     if (in_array($source->getId(), $this->_copyRecursiveIds)) {
         return;
     }
     if ($source instanceof Document_Page || $source instanceof Document_Snippet) {
         $source->getElements();
     }
     $source->getProperties();
     $new = clone $source;
     $new->id = null;
     $new->setChilds(null);
     $new->setKey(Element_Service::getSaveCopyName("document", $new->getKey(), $target));
     $new->setParentId($target->getId());
     $new->setUserOwner($this->_user->getId());
     $new->setUserModification($this->_user->getId());
     $new->setResource(null);
     $new->setLocked(false);
     $new->save();
     // add to store
     $this->_copyRecursiveIds[] = $new->getId();
     foreach ($source->getChilds() as $child) {
         $this->copyRecursive($new, $child);
     }
     $this->updateChilds($target, $new);
     return $new;
 }
示例#3
0
 public function testSetGetId()
 {
     $document = new Document($this->mandango);
     $this->assertNull($document->getId());
     $id = new \MongoId('123');
     $this->assertSame($document, $document->setId($id));
     $this->assertSame($id, $document->getId());
 }
示例#4
0
 public static function export(Document $document)
 {
     $json = db::query('SELECT creation_date, data FROM snapshots WHERE document = ' . db::value($document->getId()) . ' ORDER BY creation_date DESC');
     foreach ($json as $i => $row) {
         $json[$i]['data'] = json_decode($row['data']);
     }
     return $json;
 }
示例#5
0
 public function testSetGetId()
 {
     $document = new Document($this->mongator);
     $this->assertNull($document->getId());
     $id = new \MongoId('4af9f23d8ead0e1d32000000');
     $this->assertSame($document, $document->setId($id));
     $this->assertSame($id, $document->getId());
 }
示例#6
0
 public function newWordsAction($data = array())
 {
     $req = new Request();
     $doc = -1;
     $doc = new Document(-1);
     $data = array('docId' => $doc->getId(), 'docWords' => $doc->getWords(), 'prevWords' => '');
     return json_encode($data);
 }
示例#7
0
 public function testSetGetId()
 {
     $document = new Document($this->mandango);
     $this->assertNull($document->getId());
     $id = new \MongoDB\BSON\ObjectID($this->generateObjectId());
     $this->assertSame($document, $document->setId($id));
     $this->assertSame($id, $document->getId());
 }
示例#8
0
 public function saveAttachment(Document $document, $attachment)
 {
     $attachment_parts = pathinfo($attachment);
     $basename = $attachment_parts['basename'];
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $contentType = finfo_file($finfo, $attachment);
     $id = $document->getId();
     if (empty($id)) {
         $document->setId($document->getFields()['_id']);
     }
     $uri = sprintf('%s/%s/%s?rev=%s', $this->client->getDatabase(), $document->getId(), $basename, $document->getRevision());
     try {
         $response = $this->parseResponse($this->curl->put($this->client->getPath($uri), file_get_contents($attachment), $contentType));
     } catch (\Exception $e) {
         return $e->getMessage();
     }
     return $response;
 }
示例#9
0
 /**
  * 
  * @return boolean
  */
 public function enrich()
 {
     $this->checkValuesQuery();
     foreach ($this->properties as $xpath => $prop) {
         self::$valuesQuery->execute(array($this->document->getId(), $xpath, $this->tokenId));
         while ($value = self::$valuesQuery->fetch(\PDO::FETCH_OBJ)) {
             $user = $this->createTeiFeature('user', $value->user_id);
             $date = $this->createTeiFeature('date', $value->date);
             $xpath = $this->createTeiFeature('property_xpath', $xpath);
             $val = $this->createTeiFeature('value', $value->value);
             $fs = $this->createTeiFeatureSet();
             $fs->appendChild($user);
             $fs->appendChild($date);
             $fs->appendChild($xpath);
             $fs->appendChild($val);
             if ($prop->nodeType !== XML_ELEMENT_NODE) {
                 $prop->parentNode->appendChild($fs);
             } else {
                 $prop->appendChild($fs);
             }
         }
     }
     return $this->updateDocument();
 }
示例#10
0
 /**
  * Static helper to get a Document by it's path, only type Document is returned, not Document_Page, ... (see getConcreteByPath() )
  *
  * @param string $path
  * @return Document
  */
 public static function getByPath($path)
 {
     $path = Element_Service::correctPath($path);
     try {
         $document = new Document();
         // validate path
         if (Pimcore_Tool::isValidPath($path)) {
             $document->getResource()->getByPath($path);
         }
         return self::getById($document->getId());
     } catch (Exception $e) {
         Logger::warning($e);
     }
     return null;
 }
 /**
  * This is the constructor for the KTAPI_Document
  *
  * @author KnowledgeTree Team
  * @access private
  * @param KTAPI $ktapi The KTAPI object
  * @param KTAPI_Folder $ktapi_folder The parent folder object
  * @param Document $document The internal document object
  * @return KTAPI_Document
  */
 function KTAPI_Document(&$ktapi, &$ktapi_folder, &$document)
 {
     assert($ktapi instanceof KTAPI);
     //is_a($ktapi,'KTAPI'));
     assert(is_null($ktapi_folder) || $ktapi_folder instanceof KTAPI_Folder);
     //is_a($ktapi_folder,'KTAPI_Folder'));
     $this->ktapi =& $ktapi;
     $this->ktapi_folder =& $ktapi_folder;
     $this->document =& $document;
     $this->documentid = $document->getId();
 }
示例#12
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param Document $obj A Document object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         DocumentPeer::$instances[$key] = $obj;
     }
 }
 /**
  * Declares an association between this object and a Document object.
  *
  * @param                  Document $v
  * @return DocumentationPart The current object (for fluent API support)
  * @throws PropelException
  */
 public function setDocument(Document $v = null)
 {
     if ($v === null) {
         $this->setImageId(NULL);
     } else {
         $this->setImageId($v->getId());
     }
     $this->aDocument = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Document object, it will not be re-added.
     if ($v !== null) {
         $v->addDocumentationPart($this);
     }
     return $this;
 }
示例#14
0
 /**
  *
  * Checks if an document is an allowed relation
  * @param Document $document
  * @return boolean
  */
 protected function allowDocumentRelation($document)
 {
     $allowedDocumentTypes = $this->getDocumentTypes();
     $allowed = true;
     if (!$this->getDocumentsAllowed()) {
         $allowed = false;
     } else {
         if ($this->getDocumentsAllowed() and is_array($allowedDocumentTypes) and count($allowedDocumentTypes) > 0) {
             //check for allowed asset types
             foreach ($allowedDocumentTypes as $t) {
                 $allowedTypes[] = $t['documentTypes'];
             }
             if (!in_array($document->getType(), $allowedTypes)) {
                 $allowed = false;
             }
         } else {
             //don't check if no allowed document types set
         }
     }
     \Logger::debug("checked object relation to target document [" . $document->getId() . "] in field [" . $this->getName() . "], allowed:" . $allowed);
     return $allowed;
 }
示例#15
0
 /**
  * Удаляет документ из БД
  * @global \TDataBase $DB
  * @param \Document $doc
  */
 static function removeDocument(&$doc)
 {
     global $DB;
     $sql = 'DELETE FROM ' . TRUSTED_DB_TABLE_DOCUMENTS . '  ' . 'WHERE ID = ' . $doc->getId();
     $DB->Query($sql);
     TDataBaseDocument::saveDocumentParent($doc);
 }
示例#16
0
 /**
  * @param  User $user
  * @param  Document $childDocument
  * @param  Document $parentDocument
  * @param boolean $expanded
  * @return
  */
 protected function getTreeNodePermissionConfig($user, $childDocument, $parentDocument, $expanded)
 {
     $userGroup = $user->getParent();
     if ($userGroup instanceof User) {
         $childDocument->getPermissionsForUser($userGroup);
         $lock_list = $childDocument->isAllowed("list");
         $lock_view = $childDocument->isAllowed("view");
         $lock_save = $childDocument->isAllowed("save");
         $lock_publish = $childDocument->isAllowed("publish");
         $lock_unpublish = $childDocument->isAllowed("unpublish");
         $lock_delete = $childDocument->isAllowed("delete");
         $lock_rename = $childDocument->isAllowed("rename");
         $lock_create = $childDocument->isAllowed("create");
         $lock_permissions = $childDocument->isAllowed("permissions");
         $lock_settings = $childDocument->isAllowed("settings");
         $lock_versions = $childDocument->isAllowed("versions");
         $lock_properties = $childDocument->isAllowed("properties");
         $lock_properties = $childDocument->isAllowed("properties");
     }
     if ($parentDocument) {
         $parentDocument->getPermissionsForUser($user);
     }
     $documentPermission = $childDocument->getPermissionsForUser($user);
     $generallyAllowed = $user->isAllowed("documents");
     $parentId = (int) $childDocument->getParentId();
     $parentAllowedList = true;
     if ($parentDocument instanceof Document) {
         $parentAllowedList = $parentDocument->isAllowed("list") and $generallyAllowed;
     }
     $tmpDocument = array("_parent" => $parentId > 0 ? $parentId : null, "_id" => (int) $childDocument->getId(), "text" => $childDocument->getKey(), "type" => $childDocument->getType(), "path" => $childDocument->getFullPath(), "basePath" => $childDocument->getPath(), "elementType" => "document", "permissionSet" => $documentPermission->getId() > 0 and $documentPermission->getCid() === $childDocument->getId(), "list" => $childDocument->isAllowed("list"), "list_editable" => $parentAllowedList and $generallyAllowed and !$lock_list and !$user->isAdmin(), "view" => $childDocument->isAllowed("view"), "view_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_view and !$user->isAdmin(), "save" => $childDocument->isAllowed("save"), "save_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_save and !$user->isAdmin(), "publish" => $childDocument->isAllowed("publish"), "publish_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_publish and !$user->isAdmin(), "unpublish" => $childDocument->isAllowed("unpublish"), "unpublish_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_unpublish and !$user->isAdmin(), "delete" => $childDocument->isAllowed("delete"), "delete_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_delete and !$user->isAdmin(), "rename" => $childDocument->isAllowed("rename"), "rename_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_rename and !$user->isAdmin(), "create" => $childDocument->isAllowed("create"), "create_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_create and !$user->isAdmin(), "permissions" => $childDocument->isAllowed("permissions"), "permissions_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_permissions and !$user->isAdmin(), "settings" => $childDocument->isAllowed("settings"), "settings_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_settings and !$user->isAdmin(), "versions" => $childDocument->isAllowed("versions"), "versions_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_versions and !$user->isAdmin(), "properties" => $childDocument->isAllowed("properties"), "properties_editable" => $childDocument->isAllowed("list") and $generallyAllowed and !$lock_properties and !$user->isAdmin());
     $tmpDocument["expanded"] = $expanded;
     $tmpDocument["iconCls"] = "pimcore_icon_" . $childDocument->getType();
     // set type specific settings
     if ($childDocument->getType() == "page") {
         $tmpDocument["_is_leaf"] = $childDocument->hasNoChilds();
         $tmpDocument["iconCls"] = "pimcore_icon_page";
         // test for a site
         try {
             $site = Site::getByRootId($childDocument->getId());
             $tmpDocument["iconCls"] = "pimcore_icon_site";
             $tmpDocument["site"] = $site;
         } catch (Exception $e) {
         }
     } else {
         if ($childDocument->getType() == "folder") {
             $tmpDocument["_is_leaf"] = $childDocument->hasNoChilds();
             if ($childDocument->hasNoChilds()) {
                 $tmpDocument["iconCls"] = "pimcore_icon_folder";
             }
         } else {
             if ($childDocument->getType() == "link") {
                 $tmpDocument["_is_leaf"] = $childDocument->hasNoChilds();
                 if ($childDocument->hasNoChilds()) {
                     $tmpDocument["iconCls"] = "pimcore_icon_link";
                 }
             } else {
                 $tmpDocument["leaf"] = true;
                 $tmpDocument["_is_leaf"] = true;
             }
         }
     }
     if (!$childDocument->isPublished()) {
         $tmpDocument["cls"] = "pimcore_unpublished";
     }
     return $tmpDocument;
 }
 /**
  * Filter the query by a related Document object
  *
  * @param   Document|PropelObjectCollection $document The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return                 JournalEntryImageQuery The current query, for fluid interface
  * @throws PropelException - if the provided filter is invalid.
  */
 public function filterByDocument($document, $comparison = null)
 {
     if ($document instanceof Document) {
         return $this->addUsingAlias(JournalEntryImagePeer::DOCUMENT_ID, $document->getId(), $comparison);
     } elseif ($document instanceof PropelObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(JournalEntryImagePeer::DOCUMENT_ID, $document->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByDocument() only accepts arguments of type Document or PropelCollection');
     }
 }
示例#18
0
文件: Href.php 项目: ngocanh/pimcore
 /**
  * @see Object_Class_Data::getDataForEditmode
  * @param Asset|Document|Object_Abstract $data
  * @param null|Object_Abstract $object
  * @return array
  */
 public function getDataForEditmode($data, $object = null)
 {
     if ($data) {
         $r = array("id" => $data->getId(), "path" => $data->getFullPath());
         if ($data instanceof Document) {
             $r["subtype"] = $data->getType();
             $r["type"] = "document";
         } else {
             if ($data instanceof Asset) {
                 $r["subtype"] = $data->getType();
                 $r["type"] = "asset";
             } else {
                 if ($data instanceof Object_Abstract) {
                     $r["subtype"] = $data->getO_Type();
                     $r["type"] = "object";
                 }
             }
         }
         return $r;
     }
     return;
 }
 public function testDOMDocument()
 {
     $doc = new Document(self::$PDO);
     $doc->loadFile('sample_data/testtext.xml', 'sample_data/testtext-schema.xml', 'test', Document::DOM_DOCUMENT);
     $doc->save(self::$saveDir);
     $docId = $doc->getId();
     $this->docsToClean[] = $docId;
     $this->checkImport($docId);
     $this->insertValues($docId);
     $doc = new Document(self::$PDO);
     $doc->loadDb($docId, Document::DOM_DOCUMENT);
     $valid = trim(str_replace('<w xmlns="http://www.tei-c.org/ns/1.0"', '<w', self::$validInPlace));
     $this->assertEquals($valid, trim($doc->export(true)));
 }
示例#20
0
 /**
  * Static helper to get a Document by it's path, only type Document is returned, not Document_Page, ... (see getConcreteByPath() )
  *
  * @param string $path
  * @return Document
  */
 public static function getByPath($path)
 {
     // remove trailing slash
     if ($path != "/") {
         $path = rtrim($path, "/ ");
     }
     // correct wrong path (root-node problem)
     $path = str_replace("//", "/", $path);
     try {
         $document = new Document();
         // validate path
         if (Pimcore_Tool::isValidPath($path)) {
             $document->getResource()->getByPath($path);
         }
         return self::getById($document->getId());
     } catch (Exception $e) {
         Logger::warning($e);
     }
     return null;
 }
示例#21
0
 /**
  * This method convert a document into document link
  *
  * @param Document $document The document
  *
  * @return Fragment\Link\DocumentLink The document link
  */
 private function asLink($document)
 {
     return new Fragment\Link\DocumentLink($document->getId(), $document->getUid(), $document->getType(), $document->getTags(), $document->getSlug(), $document->getFragments(), false);
 }
示例#22
0
    foreach ($_REQUEST as $i => $v) {
        $r[join('.', explode('_', $i))] = $v;
        //convert _ back to .
    }
    $type = @$r['0'];
    $case = array();
    for ($i0 = 0; isset($r['1.' . $i0]); $i0++) {
        $case[$i0] = array('id' => @$r['1.' . $i0 . ''], 'area of law' => @$r['1.' . $i0 . '.0']);
        $case[$i0]['type of case'] = array();
        for ($i1 = 0; isset($r['1.' . $i0 . '.1.' . $i1]); $i1++) {
            $case[$i0]['type of case'][$i1] = @$r['1.' . $i0 . '.1.' . $i1 . ''];
        }
    }
    $Document = new Document($ID, $type, $case);
    if ($Document->save() !== false) {
        die('ok:' . $_SERVER['PHP_SELF'] . '?Document=' . urlencode($Document->getId()));
    } else {
        die('');
    }
    exit;
    // do not show the interface
}
$buttons = "";
if (isset($_REQUEST['new'])) {
    $new = true;
} else {
    $new = false;
}
if (isset($_REQUEST['edit']) || $new) {
    $edit = true;
} else {
示例#23
0
 /**
  * Exclude object from result
  *
  * @param   Document $document Object to remove from the list of results
  *
  * @return DocumentQuery The current query, for fluid interface
  */
 public function prune($document = null)
 {
     if ($document) {
         $this->addUsingAlias(DocumentPeer::ID, $document->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
 /**
  * Upload sentenças do WordSketch com Documento anotado em cada linha. Documentos já devem estar cadastrados.
  * Usando tags Penn do TreeTagger (para textos em inglês e espanhol)
  * @param type $data
  * @param type $file 
  */
 public function uploadSentencesPenn($data, $file)
 {
     // em cada linha: url,doc
     $idLU = $data->idLU;
     //$idCorpus = $data->idCorpus;
     $subCorpus = $data->subCorpus;
     $idLanguage = $data->idLanguage;
     $transaction = $this->beginTransaction();
     $subCorpus = $this->createSubCorpus($data);
     $documents = array();
     try {
         $sentenceNum = 0;
         $rows = file($file->getTmpName());
         foreach ($rows as $row) {
             $row = preg_replace('/#([0-9]*)/', '', $row);
             $row = trim($row);
             if ($row[0] != '#' && $row[0] != ' ' && $row[0] != '') {
                 $row = str_replace('&', 'e', $row);
                 $row = str_replace(' < ', '  <  ', $row);
                 $row = str_replace(' > ', '  >  ', $row);
                 // obtem nome do documento
                 $x = preg_match('/([^,]*),([^\\s]*)\\s/', $row, $dados);
                 if ($dados[1] != '') {
                     $docName = $dados[1];
                     mdump('==Docname ===============' . $docName);
                     $document = $documents[$docName];
                     if ($document == '') {
                         // criar Document
                         $document = new Document();
                         $document->getbyName($docName, $idLanguage);
                         if ($document->getId() == '') {
                             // não existe o documento informado na linha
                             mdump('=====');
                             mdump('== sem document: ' . $row);
                             mdump('=====');
                             continue;
                         }
                         $documents[$docName] = $document;
                     }
                     $row = trim(str_replace($dados[1] . ',' . $dados[2], '', $row));
                 } else {
                     continue;
                 }
                 $row = str_replace(array('$.', '$,', '$:', '$;', '$!', '$?', '$(', '$)', '$\'', '$"', '$--', "’", "“", "”"), array('.', ',', ':', ';', '!', '?', '(', ')', '\'', '"', '--', '\'', '"', '"'), $row);
                 $row = str_replace('</s>', ' ', $row);
                 // -- $result .= $row . "\n";
                 $tokens = preg_split('/  /', $row);
                 $tokensSize = count($tokens);
                 if ($tokensSize == 0) {
                     continue;
                 }
                 if ($tokens[0][0] == '/') {
                     $baseToken = 1;
                 } else {
                     if ($tokens[0][0] == ')') {
                         $baseToken = 1;
                     } else {
                         $baseToken = 0;
                     }
                 }
                 //mdump($tokens);
                 $sentenceNum += 1;
                 // Percorre a sentença para eliminar sentenças anteriores e posteriores (tags SENT ou FS)
                 $i = $baseToken;
                 $charCounter = 0;
                 $targetStart = -1;
                 $targetEnd = -1;
                 while ($i < $tokensSize - 1) {
                     $t = $tokens[$i];
                     $subTokens = preg_split('/\\//', $t);
                     //mdump($subTokens);
                     $word = trim($subTokens[0]);
                     $tag = trim($subTokens[1]);
                     //mdump($word);
                     if (trim($word) != '') {
                         if (trim($tag) == 'SENT' || trim($tag) == 'FS') {
                             if ($targetStart == -1) {
                                 $baseToken = $i + 1;
                                 $i += 1;
                                 continue;
                             } else {
                                 $tokensSize = $i + 2;
                                 break;
                             }
                         }
                         if ($word == '<') {
                             $i += 1;
                             $targetStart = $charCounter;
                             continue;
                         } elseif ($word == '>') {
                             $i += 1;
                             $targetEnd = $charCounter - 2;
                             continue;
                         }
                         $charCounter += strlen($word) + 1;
                     }
                     $i += 1;
                 }
                 // Build sentence and Find target
                 $isTarget = false;
                 $sentence = '';
                 $replace = ['"' => "'", '=' => ' '];
                 $search = array_keys($replace);
                 $i = $baseToken;
                 while ($i < $tokensSize - 1) {
                     $t = $tokens[$i];
                     if ($t == '<') {
                         $word = $t;
                         $isTarget = true;
                     } else {
                         if ($t == '>') {
                             $word = $t . ' ';
                             $isTarget = false;
                         } else {
                             $subTokens = preg_split('/\\//', $t);
                             $word = utf8_decode($subTokens[0]);
                             $word = str_replace($search, $replace, $word);
                             if ($isTarget) {
                                 $word = trim($word);
                             }
                         }
                     }
                     $sentence .= $word;
                     $i += 1;
                 }
                 mdump($sentence);
                 $replace = [' .' => ".", ' ,' => ',', ' ;' => ';', ' :' => ':', ' !' => '!', ' ?' => '?', ' >' => '>'];
                 $search = array_keys($replace);
                 $base = str_replace($search, $replace, $sentence);
                 $sentence = '';
                 $targetStart = -1;
                 $targetEnd = -1;
                 for ($charCounter = 0; $charCounter < strlen($base); $charCounter++) {
                     $char = $base[$charCounter];
                     if ($char == '<') {
                         $targetStart = $charCounter;
                     } elseif ($char == '>') {
                         $targetEnd = $charCounter - 2;
                     } else {
                         $sentence .= $char;
                     }
                 }
                 // Ignores lines where the target word was not detected
                 if ($targetStart == -1 || $targetEnd == -1) {
                     //  mdump('sem target: ' . $sentence);
                     continue;
                 }
                 mdump($sentence);
                 mdump($targetStart . ' - ' . $targetEnd);
                 mdump(substr($sentence, $targetStart, $targetEnd - $targetStart + 1));
                 $text = utf8_encode($sentence);
                 // -- $result .= $text . "\n";
                 $paragraph = $document->createParagraph();
                 $sentenceObj = $document->createSentence($paragraph, $sentenceNum, $text, $idLanguage);
                 $data->idSentence = $sentenceObj->getId();
                 $data->startChar = $targetStart;
                 $data->endChar = $targetEnd;
                 $subCorpus->createAnnotation($data);
                 //$data->idSentence = $sentence->getId();
                 //$data->startChar = $targetStart;
                 //$data->endChar =  $targetEnd;
                 //$subCorpus->createAnnotation($data);
             }
         }
         $transaction->commit();
     } catch (\EModelException $e) {
         // rollback da transação em caso de algum erro
         $transaction->rollback();
         throw new EModelException($e->getMessage());
     }
     return $result;
 }
示例#25
0
文件: Tool.php 项目: ngocanh/pimcore
 /**
  * @param  Document $document
  * @return string
  */
 protected static function createDocumentComparisonString($document, $ignoreCopyDifferences = false)
 {
     if ($document instanceof Document) {
         $d = array();
         if ($document instanceof Document_PageSnippet) {
             $elements = $document->getElements();
             ksort($elements);
             foreach ($elements as $key => $value) {
                 if ($value instanceof Document_Tag_Video) {
                     //with video can't use frontend(), it includes random id
                     $d["element_" . $key] = $value->getName() . ":" . $value->type . "_" . $value->id;
                 } else {
                     if (!$value instanceof Document_Tag_Block) {
                         $d["element_" . $key] = $value->getName() . ":" . $value->frontend();
                     } else {
                         $d["element_" . $key] = $value->getName();
                     }
                 }
             }
             if ($document instanceof Document_Page) {
                 $d["name"] = $document->getName();
                 $d["keywords"] = $document->getKeywords();
                 $d["title"] = $document->getTitle();
                 $d["description"] = $document->getDescription();
             }
             $d["published"] = $document->isPublished();
         }
         if ($document instanceof Document_Link) {
             $d['link'] = $document->getHtml();
         }
         if (!$ignoreCopyDifferences) {
             $d["key"] = $document->getKey();
             $d["id"] = $document->getId();
             $d["modification"] = $document->getModificationDate();
             $d["creation"] = $document->getCreationDate();
             $d["userModified"] = $document->getUserModification();
             $d["parentId"] = $document->getParentId();
             $d["path"] = $document->getPath();
         }
         $d["userOwner"] = $document->getUserOwner();
         $properties = $document->getProperties();
         $d = array_merge($d, self::createPropertiesComparisonString($properties));
         return implode(",", $d);
     } else {
         return null;
     }
 }