From the defined JSONPath(s), pull out the values and
        insert them into a document with renamed field(s) then
        apply the Extractor and return the doc with the extracted values
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
728663
@Override
	protected List<Object> extractValues(String thePaths, IBaseResource theResource) {
		IWorkerContext worker = new org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext(getContext(), myValidationSupport);
		FHIRPathEngine fp = new FHIRPathEngine(worker);
		fp.setHostServices(new SearchParamExtractorR4HostServices());

		List<Object> values = new ArrayList<>();
		String[] nextPathsSplit = SPLIT_R4.split(thePaths);
		for (String nextPath : nextPathsSplit) {
			List<Base> allValues;
			try {
				allValues = fp.evaluate((Base) theResource, nextPath);
			} catch (FHIRException e) {
				String msg = getContext().getLocalizer().getMessage(BaseSearchParamExtractor.class, "failedToExtractPaths", nextPath, e.toString());
				throw new InternalErrorException(msg, e);
			}
			if (allValues.isEmpty() == false) {
				values.addAll(allValues);
			}
		}

		for (int i = 0; i < values.size(); i++) {
			Object nextObject = values.get(i);
			if (nextObject instanceof Extension) {
				Extension nextExtension = (Extension) nextObject;
				nextObject = nextExtension.getValue();
				values.set(i, nextObject);
			}
		}

		return values;
	}
1102348
def parse_json_path(self, jsonpath):

        
        if jsonpath not in self.parsed:
            try:
                self.parsed[jsonpath] = self.parser(jsonpath)
            except Exception:
                self.log("Invalid Json Path: " + jsonpath, "error")
                raise InvalidJsonPathError("Invalid Json Path")

        return self.parsed[jsonpath]
286520
def create_doc_id_from_json(doc) -> str:
        
        return hashlib.sha256(json.dumps(doc, sort_keys=True).encode('utf-8')).hexdigest()
223017
def process_document(self, doc):
        

        descriptions = doc.select_segments("projects[*].description")
        projects = doc.select_segments("projects[*]")

        for d, p in zip(descriptions, projects):

            # First phase of extraction
            names = doc.extract(self.name_extractor, d)
            p.store(names, "members")

            # Second phase of extraction
            students = []
            for name_extraction in names:
                students += doc.extract(self.student_extractor, name_extraction)
            p.store(students, "students")
        doc.kg.add_value("developer", json_path="projects[*].members[*]")
        doc.kg.add_value("owner", json_path="projects[*].students[*]")
        return list()
167974
def document(self, result):
        
        self._add_meta(result)
        walker = JsonWalker(JsonWalker.value_json, JsonWalker.dict_expand)
        r = walker.walk(result)
        return r
501808
function getDocsToPersist(docId, view, docIdsToChangesAndEmits) {
  var metaDocId = '_local/doc_' + docId;
  var defaultMetaDoc = {_id: metaDocId, keys: []};
  var docData = docIdsToChangesAndEmits[docId];
  var indexableKeysToKeyValues = docData.indexableKeysToKeyValues;
  var changes = docData.changes;

  function getMetaDoc() {
    if (isGenOne(changes)) {
      // generation 1, so we can safely assume initial state
      // for performance reasons (avoids unnecessary GETs)
      return Promise.resolve(defaultMetaDoc);
    }
    return view.db.get(metaDocId).catch(defaultsTo(defaultMetaDoc));
  }

  function getKeyValueDocs(metaDoc) {
    if (!metaDoc.keys.length) {
      // no keys, no need for a lookup
      return Promise.resolve({rows: []});
    }
    return view.db.allDocs({
      keys: metaDoc.keys,
      include_docs: true
    });
  }

  function processKvDocs(metaDoc, kvDocsRes) {
    var kvDocs = [];
    var oldKeysMap = {};

    for (var i = 0, len = kvDocsRes.rows.length; i < len; i++) {
      var row = kvDocsRes.rows[i];
      var doc = row.doc;
      if (!doc) { // deleted
        continue;
      }
      kvDocs.push(doc);
      oldKeysMap[doc._id] = true;
      doc._deleted = !indexableKeysToKeyValues[doc._id];
      if (!doc._deleted) {
        var keyValue = indexableKeysToKeyValues[doc._id];
        if ('value' in keyValue) {
          doc.value = keyValue.value;
        }
      }
    }

    var newKeys = Object.keys(indexableKeysToKeyValues);
    newKeys.forEach(function (key) {
      if (!oldKeysMap[key]) {
        // new doc
        var kvDoc = {
          _id: key
        };
        var keyValue = indexableKeysToKeyValues[key];
        if ('value' in keyValue) {
          kvDoc.value = keyValue.value;
        }
        kvDocs.push(kvDoc);
      }
    });
    metaDoc.keys = uniq(newKeys.concat(metaDoc.keys));
    kvDocs.push(metaDoc);

    return kvDocs;
  }

  return getMetaDoc().then(function (metaDoc) {
    return getKeyValueDocs(metaDoc).then(function (kvDocsRes) {
      return processKvDocs(metaDoc, kvDocsRes);
    });
  });
}
217611
def from_json(cls, json):
        ''' 

        '''
        roots_json = json['roots']
        root_ids = roots_json['root_ids']
        references_json = roots_json['references']

        references = instantiate_references_json(references_json)
        initialize_references_json(references_json, references)

        doc = Document()
        for r in root_ids:
            doc.add_root(references[r])

        doc.title = json['title']

        return doc
357762
public static void extractText(JCas jcas, BDocument bDocument,
            String docId, boolean expandAbbrevs) {

        StringBuffer sb = new StringBuffer("");
        int currBegin = 0, currPageId = 0;

        DocumentPage currPage = new DocumentPage(jcas);
        currPage.setBegin(0);

        Set<Abbrev> abbrevs = null;
        if (expandAbbrevs) {
            // pass over the text to find abbrevs
            StringBuffer abbrevSb = new StringBuffer("");
            for (BBlock block : bDocument.getBlocks()) {
                abbrevSb.append(cleanupText(block, docId));
            }
            abbrevs = AbbreviationExpander.getAbbrevs(abbrevSb.toString());
        }

        for (BBlock block : bDocument.getBlocks()) {

            String text = cleanupText(block, docId);
            if (expandAbbrevs) {
                text = AbbreviationExpander.expand(text, abbrevs);
            }

            // add lines
            int currLineBegin = currBegin;
            for (BLine bLine : block.getLines()) {
                String lineText = bLine.getText();
                int lineLength = lineText.replaceAll(" +", " ").length();
                // LATER watch out: begin,end is ~approximate~
                // TODO especially because of abbrev expansion!
                DocumentLine annLine = new DocumentLine(jcas, currLineBegin,
                        currLineBegin + lineLength);
                currLineBegin += lineLength;
                annLine.setX(bLine.getRegion().x);
                annLine.setY(bLine.getRegion().y);
                annLine.setHeight(bLine.getRegion().height);
                annLine.setWidth(bLine.getRegion().width);
                annLine.setPageId(block.getPageId());
                annLine.setBlock(block.getId());
                annLine.setLineText(lineText); // LATER a workaround
                annLine.setBeginnings(new FloatArray(jcas, bLine
                        .getBeginnings().size()));
                for (int i = 0; i < bLine.getBeginnings().size(); i++) {
                    annLine.setBeginnings(i, bLine.getBeginnings().get(i));
                }
                annLine.setEndings(new FloatArray(jcas, bLine.getEndings()
                        .size()));
                for (int i = 0; i < bLine.getEndings().size(); i++) {
                    annLine.setEndings(i, bLine.getEndings().get(i));
                }
                annLine.addToIndexes();
            }

            // add block
            DocumentBlock annBlock = new DocumentBlock(jcas, currBegin,
                    currBegin + text.length());
            currBegin += text.length();
            sb.append(text);

            annBlock.setElementId(block.getId());
            annBlock.setX(block.getRegion().x);
            annBlock.setY(block.getRegion().y);
            annBlock.setHeight(block.getRegion().height);
            annBlock.setWidth(block.getRegion().width);
            annBlock.setHasBold(block.isHasBold());
            annBlock.setHasManyFontsizes(block.isHasManyFontsizes());
            annBlock.setMedianFontsize(block.getMedianFontsize());
            annBlock.setPageId(block.getPageId());
            annBlock.addToIndexes();

            // update page
            if (block.getPageId() > currPageId) {
                currPage.setEnd(currBegin);
                currPage.setPageId(currPageId);
                currPage.addToIndexes();

                currPage = new DocumentPage(jcas);
                currPage.setBegin(currBegin);
                currPageId = block.getPageId();
            }
        }

        jcas.setDocumentText(sb.toString());
    }
1226506
function extractSamplesFromDocuIndex(oChainObject) {
		// If we have not extracted docuPath we return early
		if (!oChainObject.docuPath) {
			return oChainObject;
		}
		return new Promise(function(oResolve) {
			// Join .library path with relative docuindex.json path
			let sPath = path.join(path.dirname(oChainObject.libraryFile), oChainObject.docuPath);
			// Normalize path to resolve relative path
			sPath = path.normalize(sPath);

			fs.readFile(sPath, 'utf8', (oError, oFileData) => {
				if (!oError) {
					oFileData = JSON.parse(oFileData);
					if (oFileData.explored && oFileData.explored.entities && oFileData.explored.entities.length > 0) {
						oChainObject.entitiesWithSamples = [];
						oFileData.explored.entities.forEach(oEntity => {
							oChainObject.entitiesWithSamples.push(oEntity.id);
						});
					}
				}
				// We aways resolve as this data is not mandatory
				oResolve(oChainObject);
			});

		});
	}
470896
def jsondel(self, name, path=Path.rootPath()):
        
        return self.execute_command('JSON.DEL', name, str_path(path))
1089542
def write(self, values):
        
        # Insert only for docs targeted by the target
        filtered = {_id: value for _id, value in values.items() if _id in self._document_ids}

        if not filtered:
            return

        bulk = self.get_collection().initialize_ordered_bulk_op()
        for _id, value in filtered.items():
            bulk.find({'_id': _id}).upsert() \
                    .update_one({'$set': {self._field: value}})

        bulk.execute()
839512
private Map<String, Object> documentToPackableMap(Map<String, Object> document) {
        if (compatibleValues) {
            try {
                return jsonMapper.readValue(jsonMapper.writeValueAsBytes(document), new TypeReference<Map<String, Object>>() {
                });
            } catch (Exception e) {
                throw new RuntimeException("Cannot convert document to json and back to Map " + e.getMessage());
            }
        }

        /**
         * A document in MongoDB has a special field "_id" of type ObjectId
         * This object is not "packable" by Neo4jPacker so it must be converted to a value that Neo4j can deal with
         *
         * If the document is not null we simply override the ObjectId instance with its string representation
         */

        if (document != null) {
            Object objectId = document.get("_id");
            if (objectId != null) {
                document.put("_id", objectId.toString());
            }

        }

        return document;
    }
811582
def json_get(json_object, property_path, default=None):
    
    temp = json_object
    for field in property_path[:-1]:
        if not isinstance(temp, dict):
            return None
        temp = temp.get(field, {})
    if not isinstance(temp, dict):
        return None
    return temp.get(property_path[-1], default)
178224
function() {
				var doc = this;
				var outDoc = doc.toObject(); // Rely on the toObject() syntax to strip out rubbish

				doc.getOIDs().forEach(function(node) {
					switch (node.fkType) {
						case 'objectId':
							var oidLeaf = _.get(doc, node.docPath);
							if (_.isUndefined(oidLeaf)) return; // Ignore undefined

							if (!o.utilities.isObjectID(oidLeaf)) {
								if (_.has(oidLeaf, '_id')) { // Already populated?
									_.set(outDoc, node.docPath, o.utilities.objectID(oidLeaf._id));
								} else { // Convert to an OID
									_.set(outDoc, node.docPath, o.utilities.objectID(oidLeaf));
								}
							}
							break;
						case 'objectIdArray':
							var oidLeaf = _.get(doc, node.schemaPath);
							_.set(outDoc, node.schemaPath, oidLeaf.map(function(leaf) {
								return o.utilities.isObjectID(leaf) ? leaf : o.utilities.objectID(leaf);
							}));
							break;
						default:
							return; // Ignore unsupported OID types
					}
				});

				return outDoc;
			}
1185271
def extract_from_renamed_inputs(self, doc, renamed_inputs):
        """"""
        extracted_value = self.extractor.extract(renamed_inputs)
        if not extracted_value:
            return doc

        if self.output_fields is not None and isinstance(extracted_value, dict):
            if isinstance(self.output_fields, list):
                for field in self.output_fields:
                    if field in extracted_value:
                        self.insert_extracted_value(
                            doc, extracted_value[field], field)
            elif isinstance(self.output_fields, dict):
                for key, value in self.output_fields.iteritems():
                    if key in extracted_value:
                        self.insert_extracted_value(
                            doc, extracted_value[key], value, key)
        else:
            self.insert_extracted_value(
                doc, extracted_value, self.output_field)
885208
@Override
    @Path("/{documentId}")
    public JSONObject get(String path, Map<String,String> headers)
    throws ServiceException, JSONException {
        WorkflowServices workflowServices = ServiceLocator.getWorkflowServices();
        String docId = getSegment(path, 1);
        if (docId == null) {
            throw new ServiceException(ServiceException.BAD_REQUEST, "Invalid path: " + path);
        }
        try {
            JSONObject json = new JSONObject();
            json.put("value", workflowServices.getDocumentStringValue(Long.valueOf(docId)));
            return json;
        }
        catch (NumberFormatException e) {
            throw new ServiceException(ServiceException.BAD_REQUEST, "Invalid path: " + path, e);
        }
    }