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

def extract(self, doc):
        """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  """
        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