Formats the document for use in \SVMModel
@param  string                                          $document
@param  \Camspiers\StatisticalClassifier\Model\SVMModel $model
@return array
508121
protected function prepareDocument($document, SVMModel $model)
    {
        $tokenMap = $model->getTokenMap();

        $data = array();

        if ($this->documentNormalizer) {
            $document = $this->documentNormalizer->normalize($document);
        }

        $tokens = $this->tokenizer->tokenize($document);

        if ($this->tokenNormalizer) {
            $tokens = $this->tokenNormalizer->normalize($tokens);
        }

        $tokenCounts = array_count_values($tokens);

        foreach ($tokenCounts as $token => $value) {
            if (isset($tokenMap[$token])) {
                $data[$tokenMap[$token]] = $value;
            }
        }

        ksort($data, SORT_NUMERIC);

        return $data;
    }
1257870
private function createStructure($document)
    {
        return new ManagedStructure(
            $this->contentTypeManager,
            $this->legacyPropertyFactory,
            $this->inspector,
            $document
        );
    }
565071
public function toRdf(array $document)
    {
        $nodeMap = new JsonObject();
        $nodeMap->{'-' . JsonLD::DEFAULT_GRAPH} = new JsonObject();

        $this->generateNodeMap($nodeMap, $document);

        $result = array();

        foreach ($nodeMap as $graphName => $graph) {
            $graphName = substr($graphName, 1);
            if (JsonLD::DEFAULT_GRAPH === $graphName) {
                $activegraph = null;
            } else {
                $activegraph = new IRI($graphName);

                if (false === $activegraph->isAbsolute()) {
                    continue;
                }
            }

            foreach ($graph as $subject => $node) {
                $activesubj = new IRI(substr($subject, 1));

                if (false === $activesubj->isAbsolute()) {
                    continue;
                }

                foreach ($node as $property => $values) {
                    if ('@id' === $property) {
                        continue;
                    } elseif ('@type' === $property) {
                        $activeprty = new IRI(RdfConstants::RDF_TYPE);
                        foreach ($values as $value) {
                            $result[] = new Quad($activesubj, $activeprty, new IRI($value), $activegraph);
                        }

                        continue;
                    } elseif ('@' === $property[0]) {
                        continue;
                    }

                    // Exclude triples/quads with a blank node predicate if generalized RDF isn't enabled
                    if ((0 === strncmp($property, '_:', 2)) && (false === $this->generalizedRdf)) {
                        continue;
                    }

                    $activeprty = new IRI($property);
                    if (false === $activeprty->isAbsolute()) {
                        continue;
                    }

                    foreach ($values as $value) {
                        if (property_exists($value, '@list')) {
                            $quads = array();
                            $head = $this->listToRdf($value->{'@list'}, $quads, $activegraph);

                            $result[] = new Quad($activesubj, $activeprty, $head, $activegraph);
                            foreach ($quads as $quad) {
                                $result[] = $quad;
                            }
                        } else {
                            $object = $this->elementToRdf($value);

                            if (null === $object) {
                                continue;
                            }

                            $result[] = new Quad($activesubj, $activeprty, $object, $activegraph);
                        }
                    }
                }
            }
        }

        return $result;
    }
1207145
public function getNormalizedIdentifier($document)
    {
        if (is_scalar($document)) {
            throw new \InvalidArgumentException('Invalid argument, object or null required');
        }

        // the document is not managed
        if (!$document || !$this->getDocumentManager()->contains($document)) {
            return;
        }

        $values = $this->getIdentifierValues($document);

        return $values[0];
    }
932541
public function prepareInsertData($document)
    {
        $class     = $this->dm->getClassMetadata(get_class($document));
        $changeset = $this->uow->getDocumentChangeSet($document);

        $insertData = [];
        foreach ($class->fieldMappings as $mapping) {
            $new = $changeset[$mapping['fieldName']][1] ?? null;

            if ($new === null && $mapping['nullable']) {
                $insertData[$mapping['name']] = null;
            }

            /* Nothing more to do for null values, since we're either storing
             * them (if nullable was true) or not.
             */
            if ($new === null) {
                continue;
            }

            // @Field, @String, @Date, etc.
            if (! isset($mapping['association'])) {
                $insertData[$mapping['name']] = Type::getType($mapping['type'])->convertToDatabaseValue($new);

            // @ReferenceOne
            } elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
                $insertData[$mapping['name']] = $this->prepareReferencedDocumentValue($mapping, $new);

            // @EmbedOne
            } elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_ONE) {
                $insertData[$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);

            // @ReferenceMany, @EmbedMany
            // We're excluding collections using addToSet since there is a risk
            // of duplicated entries stored in the collection
            } elseif ($mapping['type'] === ClassMetadata::MANY && ! $mapping['isInverseSide']
                    && $mapping['strategy'] !== ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET && ! $new->isEmpty()) {
                $insertData[$mapping['name']] = $this->prepareAssociatedCollectionValue($new, true);
            }
        }

        // add discriminator if the class has one
        if (isset($class->discriminatorField)) {
            $discriminatorValue = $class->discriminatorValue;

            if ($discriminatorValue === null) {
                if (! empty($class->discriminatorMap)) {
                    throw MappingException::unlistedClassInDiscriminatorMap($class->name);
                }

                $discriminatorValue = $class->name;
            }

            $insertData[$class->discriminatorField] = $discriminatorValue;
        }

        return $insertData;
    }
166049
protected function getHashId(Document $document, $sm) 
	{
		$main = $sm->get('neobazaar.service.main');
		$documentRepository = $main->getDocumentEntityRepository();
		return $documentRepository->getEncryptedId($document->getDocumentId());
	}
700186
public function getLocalesFor($document)
    {
        $metadata = $this->dm->getClassMetadata(get_class($document));
        if (!$this->isDocumentTranslatable($metadata)) {
            throw new MissingTranslationException('This document is not translatable: : '.self::objToStr($document, $this->dm));
        }

        $oid = spl_object_hash($document);
        if ($this->contains($oid)) {
            try {
                $node = $this->session->getNode($this->getDocumentId($document));
                $locales = $this->dm->getTranslationStrategy($metadata->translator)->getLocalesFor($document, $node, $metadata);
            } catch (PathNotFoundException $e) {
                $locales = [];
            }
        } else {
            $locales = [];
        }

        if (isset($this->documentTranslations[$oid])) {
            foreach ($this->documentTranslations[$oid] as $locale => $value) {
                if (!in_array($locale, $locales)) {
                    if ($value) {
                        $locales[] = $locale;
                    }
                } elseif (!$value) {
                    $key = array_search($locale, $locales);
                    unset($locales[$key]);
                }
            }

            $locales = array_values($locales);
        }

        return $locales;
    }
1204213
public function getOriginalDocumentData($document)
    {
        $oid = spl_object_hash($document);
        if (isset($this->originalDocumentData[$oid])) {
            return $this->originalDocumentData[$oid];
        }
        return array();
    }
729983
protected function _documentToXmlFragment(Apache_Solr_Document $document)
	{
		$xml = '<doc';

		if ($document->getBoost() !== false)
		{
			$xml .= ' boost="' . $document->getBoost() . '"';
		}

		$xml .= '>';

		foreach ($document as $key => $value)
		{
			$fieldBoost = $document->getFieldBoost($key);
			$key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');

			if (is_array($value))
			{
				foreach ($value as $multivalue)
				{
					$xml .= '<field name="' . $key . '"';

					if ($fieldBoost !== false)
					{
						$xml .= ' boost="' . $fieldBoost . '"';

						// only set the boost for the first field in the set
						$fieldBoost = false;
					}

					$multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');

					$xml .= '>' . $multivalue . '</field>';
				}
			}
			else
			{
				$xml .= '<field name="' . $key . '"';

				if ($fieldBoost !== false)
				{
					$xml .= ' boost="' . $fieldBoost . '"';
				}

				$value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');

				$xml .= '>' . $value . '</field>';
			}
		}

		$xml .= '</doc>';

		// replace any control characters to avoid Solr XML parser exception
		return $this->_stripCtrlChars($xml);
	}
1267675
protected function encodeLiteral(DOMDocument $document)
    {
        $xpath = new DOMXPath($document);

        $xpathExpression = '//literal[not(@class="html")]';

        $elements = $xpath->query($xpathExpression);

        foreach ($elements as $element) {
            $element->textContent = str_replace(']]>', ']]]]><![CDATA[>', $element->textContent);
        }
    }
1177338
public function parseDocument(\DOMDocument $document)
    {
        foreach ($this->registry[DocumentExtension::class] as $extension) {
            $doc = $extension->parseDocument($this, $document);
            if ($doc) {
                return $doc;
            }
        }

        return null;
    }
796830
public function convert(DOMDocument $document)
    {
        // First
        $this->expandingConverter->convert($document);
        // Second
        $this->embedLinkingConverter->convert($document);

        return $document;
    }
636710
static public function inferVersion(DOMDocument $document)
    {
        $root = $document->documentElement;
        $version = false;
        
        if (empty($root) === false) {
            $rootNs = $root->namespaceURI;
            
            if ($rootNs === 'http://www.imsglobal.org/xsd/imsqti_v2p0') {
                $nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsqti_v2p0');
                
                if ($nsLocation === 'http://www.imsglobal.org/xsd/imsqti_v2p0.xsd') {
                    $version = '2.0.0';
                }
            } elseif ($rootNs === 'http://www.imsglobal.org/xsd/imsqti_v2p1') {
                $nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsqti_v2p1');
                
                if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd') {
                    $version = '2.1.0';
                } else if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1p1.xsd') {
                    $version = '2.1.1';
                }
            } elseif ($rootNs === 'http://www.imsglobal.org/xsd/imsqti_v2p2') {
                $nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsqti_v2p2');
                
                if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2.xsd') {
                    $version = '2.2.0';
                } elseif ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2p1.xsd') {
                    $version = '2.2.1';
                }
            } elseif ($rootNs === 'http://www.imsglobal.org/xsd/imsaqti_item_v1p0') {
                $nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsaqti_item_v1p0');
                
                if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/aqtiv1p0/imsaqti_itemv1p0_v1p0.xsd') {
                    $version = '3.0.0';
                }
            }
        }
        
        return $version;
    }
1198171
protected function getStateFormatted(Document $document) 
	{
		switch($document->getState()) {
			case Document::DOCUMENT_STATE_ACTIVE:
				$this->stateClass = 'success';
				return 'Attivo';
				break;
			case Document::DOCUMENT_STATE_DEACTIVE:
				$this->stateClass = 'warning';
				return 'Disattivo';
				break;
			case Document::DOCUMENT_STATE_DELETED:
				$this->stateClass = 'danger';
				return 'Eliminato';
				break;
		}

		$this->stateClass = 'danger';
		return 'Error with document state';
	}
531923
public function formatReturn($doc = [])
    {
        $json = '{<br>';
        $data = $this->config['return_format'];
        $returns = isset($doc['return']) ? $doc['return'] : [];
        foreach ($data as $name=>$value) {
            if($name != 'data' || (empty($returns) && $name == 'data')){
                $json .= '&nbsp;&nbsp;"'.$name.'":'.$value.',<br>';
            }
        }
        if( !empty($returns) ) {
            $json .= '&nbsp;&nbsp;"data":{<br/>';
            foreach ($returns as $val)
            {
                list($name, $value) =  explode(":", trim($val));
                if(strpos($value, '@') != false){
                    $json .= $this->string2jsonArray($doc, $val, '&nbsp;&nbsp;&nbsp;&nbsp;');
                }else{
                    $json .= '&nbsp;&nbsp;&nbsp;&nbsp;' . $this->string2json(trim($name), $value);
                }
            }
            $json .= '&nbsp;&nbsp;}<br/>';
        }
        $json .= '}';
        return $json;
    }
1222802
private function getQueryForDocument(object $document) : array
    {
        $id = $this->uow->getDocumentIdentifier($document);
        $id = $this->class->getDatabaseIdentifierValue($id);

        $shardKeyQueryPart = $this->getShardKeyQuery($document);
        return array_merge(['_id' => $id], $shardKeyQueryPart);
    }
1013554
def model_to_document(model)
      document = model.attributes.dup.except(:key, :rev)

      handle_embedded_models(model, document)
      handle_related_models(document)

      document
    end