Convert an estnltk document to an estner document.

    Parameters
    ----------
    jsondoc: dict
        Estnltk JSON-style document.

    Returns
    -------
    estnltk.estner.ner.Document
        A ner document.
328183
def json_document_to_estner_document(jsondoc):
    
    sentences = []
    for json_sent in jsondoc.split_by_sentences():
        snt = Sentence()
        zipped = list(zip(
            json_sent.word_texts,
            json_sent.lemmas,
            json_sent.root_tokens,
            json_sent.forms,
            json_sent.endings,
            json_sent.postags))
        json_toks = [{TEXT: text, LEMMA: lemma, ROOT_TOKENS: root_tokens, FORM: form, ENDING: ending, POSTAG: postag}
                     for text, lemma, root_tokens, form, ending, postag in zipped]
        # add labels, if they are present
        for tok, word in zip(json_toks, json_sent.words):
            if LABEL in word:
                tok[LABEL] = word[LABEL]
        for json_tok in json_toks:
            token = json_token_to_estner_token(json_tok)
            snt.append(token)
        if snt:
            for i in range(1, len(snt)):
                snt[i - 1].next = snt[i]
                snt[i].prew = snt[i - 1]
            sentences.append(snt)
    return Document(sentences=sentences)
185404
def to_json(self):
        
        json_data = dict()

        for field_name, field_obj in self._fields.items():
            if isinstance(field_obj, NestedDocumentField):
                nested_document = field_obj.__get__(self, self.__class__)
                value = None if nested_document is None else nested_document.to_json()
            elif isinstance(field_obj, BaseField):
                value = field_obj.__get__(self, self.__class__)
                value = field_obj.to_json(value)
            else:
                # ignore fields not derived from BaseField or NestedDocument
                continue

            if value is None:
                # skip fields with None value 
                continue

            json_data[field_name] = value

        return json_data
331042
def extract(self, doc):
        
        if isinstance(self.jsonpaths, JSONPath):
            input_field = self.extractor.get_renamed_input_fields()
            if isinstance(self.extractor.get_renamed_input_fields(), list):
                input_field = input_field[0]

            jsonpath = self.jsonpaths
            renamed_inputs = dict()
            if self.flat_map_inputs:
                flat_mapped = itertools.chain.from_iterable(
                    [iter(match.value)
                     if hasattr(match.value, '__iter__') and
                     not isinstance(match.value, dict) and
                     not isinstance(match.value, basestring)
                     else iter([match.value])
                     for match in jsonpath.find(doc)])
                renamed_inputs[input_field] = flat_mapped
                if input_field in renamed_inputs:
                    self.extract_from_renamed_inputs(doc, renamed_inputs)

            else:
                for value in [match.value for match in jsonpath.find(doc)]:
                    renamed_inputs[input_field] = value
                    self.extract_from_renamed_inputs(doc, renamed_inputs)

        elif isinstance(self.jsonpaths, types.ListType):

            renamed_inputs_lists = dict()
            for jsonpath, renamed_input in \
                    itertools.izip(
                    iter(self.jsonpaths),
                    iter(self.extractor.get_renamed_input_fields())):
                renamed_inputs_lists[renamed_input] = [
                    match.value for match in jsonpath.find(doc)]

            if self.flat_map_inputs:
                renamed_inputs_tuple_lists = [
                    (x, itertools.chain.from_iterable(
                        [iter(z) if hasattr(z, '__iter__') and
                         not isinstance(z, dict) and
                         not isinstance(z, basestring)
                         else iter([z])for z in y]))
                    for x, y in renamed_inputs_lists.iteritems()]
                renamed_inputs = reduce(
                    ExtractorProcessor.add_tuple_to_doc,
                    renamed_inputs_tuple_lists, dict())
                self.extract_from_renamed_inputs(doc, renamed_inputs)
            else:
                renamed_inputs_lists_lists = [[(x, z) for z in y]
                                              for x, y in
                                              renamed_inputs_lists.iteritems()]
                for i in itertools.product(*renamed_inputs_lists_lists):
                    renamed_inputs = reduce(
                        ExtractorProcessor.add_tuple_to_doc, i, dict())
                    self.extract_from_renamed_inputs(doc, renamed_inputs)
        else:
            raise ValueError("input_fields must be a string or a list")

        return doc
624056
def to_json(self):
    
    cursor = self._get_cursor()
    cursor_object = False
    if cursor and isinstance(cursor, datastore_query.Cursor):
      cursor = cursor.to_websafe_string()
      cursor_object = True
    return {"key_range": self._key_range.to_json(),
            "query_spec": self._query_spec.to_json(),
            "cursor": cursor,
            "cursor_object": cursor_object}
16872
def _build_document_converter(cls, session: AppSession):
        ''''''

        if not session.args.convert_links:
            return

        converter = session.factory.new(
            'BatchDocumentConverter',
            session.factory['HTMLParser'],
            session.factory['ElementWalker'],
            session.factory['URLTable'],
            backup=session.args.backup_converted
        )

        return converter
834268
public static JsonNode getFieldValue(JsonNode doc, String field) {
        StringTokenizer tkz = new StringTokenizer(field, ". ");
        JsonNode trc = doc;
        while (tkz.hasMoreTokens() && trc != null) {
            String tok = tkz.nextToken();
            trc = trc.get(tok);
        }
        return trc;
    }
1125143
def to_json(self, *, include=None):
        '''  '''
        json = dict()

        if include is None or 'id' in include or '*' in include:
            json['id'] = self.id

        if include is None or '_type' in include or '*' in include:
            json['_type'] = type(self).cls_key()

        def fieldfilter(fieldtuple):
            return \
                not fieldtuple[1].private and \
                not isinstance(fieldtuple[1], Relation) and (
                    include is None or fieldtuple[0] in include or '*' in include
                )

        json.update(dict(starmap(
            lambda fn, f: (fn, f.to_json(getattr(self, fn))),
            filter(
                fieldfilter,
                self.proxy
            )
        )))

        for requested_relation in parse_embed(include):
            relation_name, subfields = requested_relation

            if not hasattr(self.proxy, relation_name):
                continue

            relation = getattr(self.proxy, relation_name)

            if isinstance(relation, ForeignIdRelation):
                item = relation.get()

                if item is not None:
                    json[relation_name] = item.to_json(include=subfields)
                else:
                    json[relation_name] = None
            elif isinstance(relation, MultipleRelation):
                json[relation_name] = list(map(lambda o: o.to_json(include=subfields), relation.get()))

        return json
512827
def to_json(self):
        

        result = super(ContentType, self).to_json()
        result.update({
            'name': self.name,
            'description': self.description,
            'displayField': self.display_field,
            'fields': [f.to_json() for f in self.fields]
        })
        return result
658534
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'document_label' in _dict:
            args['document_label'] = _dict.get('document_label')
        if 'location' in _dict:
            args['location'] = Location._from_dict(_dict.get('location'))
        if 'text' in _dict:
            args['text'] = _dict.get('text')
        if 'types' in _dict:
            args['types'] = [
                TypeLabelComparison._from_dict(x) for x in (_dict.get('types'))
            ]
        if 'categories' in _dict:
            args['categories'] = [
                CategoryComparison._from_dict(x)
                for x in (_dict.get('categories'))
            ]
        if 'attributes' in _dict:
            args['attributes'] = [
                Attribute._from_dict(x) for x in (_dict.get('attributes'))
            ]
        return cls(**args)
827478
def from_json(cls, json_data):
        
        new_instance = cls()
        for field_name, field_obj in cls._get_fields().items():
            if isinstance(field_obj, NestedDocumentField):
                if field_name in json_data:
                    nested_field = field_obj.__get__(new_instance, new_instance.__class__)
                    if not nested_field:
                        # here, we have to create an instance of the nested document,
                        # since we have a JSON object for it
                        nested_field = field_obj.nested_klass()

                    nested_document = nested_field.from_json(json_data[field_name])
                    field_obj.__set__(new_instance, nested_document)
            elif isinstance(field_obj, BaseField):
                if field_name in json_data:
                    value = field_obj.from_json(json_data[field_name])
                    field_obj.__set__(new_instance, value)
            else:
                continue

        return new_instance
508498
def _schema_to_json_file_object(self, schema_list, file_obj):
        
        json.dump(schema_list, file_obj, indent=2, sort_keys=True)
725708
def to_json(self, minimal=True):
        
        if minimal:
            return json.dumps(self.json_repr(minimal=True), cls=MarathonMinimalJsonEncoder, sort_keys=True)
        else:
            return json.dumps(self.json_repr(), cls=MarathonJsonEncoder, sort_keys=True)
1235206
def _to_json(self, include_references=True):
        
        if include_references:
            return json.dumps(self._resource._properties, cls=PotionJSONEncoder)
        else:
            return json.dumps(
                {
                    k: v
                    for k, v in self._resource._properties.items()
                    if not isinstance(v, Resource) and not k.startswith("$")
                },
                cls=PotionJSONEncoder,
            )
1305103
@Override
    public void newDoc() throws IOException {
        sb = new StringBuilder();
        baos = new ByteArrayOutputStream();
        generator = jsonFactory.createJsonGenerator(baos);
        generator.writeStartObject(); 
    }
1006732
def to_json(self, filename=None):
        
        def json_encoder(obj):
            if isinstance(obj, pd.DataFrame) or isinstance(obj, pd.Series):
                if isinstance(obj.index, pd.core.index.MultiIndex):
                    obj = obj.reset_index()  # convert MultiIndex to columns

                return json.loads(obj.to_json(date_format='iso'))
            elif isinstance(obj, melodist.cascade.CascadeStatistics):
                return obj.__dict__
            elif isinstance(obj, np.ndarray):
                return obj.tolist()
            else:
                raise TypeError('%s not supported' % type(obj))

        d = dict(
            temp=self.temp,
            wind=self.wind,
            precip=self.precip,
            hum=self.hum,
            glob=self.glob
        )

        j = json.dumps(d, default=json_encoder, indent=4)

        if filename is None:
            return j
        else:
            with open(filename, 'w') as f:
                f.write(j)
205127
function fromRawDoc(pouchDoc) {
    var obj = pouchDoc.data;
    obj.id = deserialize(pouchDoc._id);
    obj.rev = pouchDoc._rev;
    if (pouchDoc._attachments) {
      obj.attachments = pouchDoc._attachments;
    }
    return obj;
  }
1329396
def apply_docstr(docstr_func):
    
    def docstr_applier(func):
        #docstr = meta_util_six.get_funcdoc(docstr_func)
        #meta_util_six.set_funcdoc(func, docstr)
        if isinstance(docstr_func, six.string_types):
            olddoc = meta_util_six.get_funcdoc(func)
            if olddoc is None:
                olddoc = ''
            newdoc = olddoc + docstr_func
            meta_util_six.set_funcdoc(func, newdoc)
            return func
        else:
            preserved_func = preserve_sig(func, docstr_func)
            return preserved_func
    return docstr_applier