Construct a Xapian term
179974
def mkterm type, *args
    case type
    when :label
      PREFIX['label'][:prefix] + args[0].to_s.downcase
    when :type
      PREFIX['type'][:prefix] + args[0].to_s.downcase
    when :date
      PREFIX['date'][:prefix] + args[0].getutc.strftime("%Y%m%d%H%M%S")
    when :email
      case args[0]
      when :from then PREFIX['from_email'][:prefix]
      when :to then PREFIX['to_email'][:prefix]
      else raise "Invalid email term type #{args[0]}"
      end + args[1].to_s.downcase
    when :source_id
      PREFIX['source_id'][:prefix] + args[0].to_s.downcase
    when :location
      PREFIX['location'][:prefix] + [args[0]].pack('n') + args[1].to_s
    when :attachment_extension
      PREFIX['attachment_extension'][:prefix] + args[0].to_s.downcase
    when :msgid, :ref, :thread
      PREFIX[type.to_s][:prefix] + args[0][0...(MAX_TERM_LENGTH-1)]
    else
      raise "Invalid term type #{type}"
    end
  end
18897
private void termsApiUsage() throws JsonProcessingException, ApiException {
        /**
         * 
         */
        LOG.info("The Terms API usage.");
        Terms api = retinaApisInstance.termsApi();
        /**
         * 
         */
        LOG.info("Terms API: getContextsForTerm");
        List<Context> contexts = api.getContexts("apple");
        logContext(contexts);
        contexts = api.getContexts("apple", new Pagination(0, 2), true);
        
        logContext(contexts);
        /**
         * 
         */
        List<Term> terms;
        LOG.info("Terms API: getSimilarTerms");
        
        terms = api.getSimilarTerms("tiger");
        
        logTerms(terms);
        
        terms = api.getSimilarTerms("tiger", null, PosType.NOUN);
        
        logTerms(terms);
        
        //**** ERROR *****
        terms = api.getSimilarTerms("tiger", null, PosType.NOUN, true);
        logTerms(terms);
        /**
         * 
         */
        LOG.info("Terms API: getTerm");
        terms = api.getTerm("apple");
        logTerms(terms);
        System.out.println();
        
        terms = api.getTerm("banana", new Pagination(0, 2), true);
        logTerms(terms);
        System.out.println();
        
        LOG.info("Terms API: getTerm NULL TEST");
        terms = api.getTerm(null);
        logTerms(terms);
    }
483311
def _term_query(self, term, field_name, field_type, stemmed=True):
        
        constructor = '{prefix}{term}'

        # construct the prefix to be used.
        prefix = ''
        if field_name:
            prefix = TERM_PREFIXES['field'] + field_name.upper()
            term = _to_xapian_term(term)

        if field_name in (ID, DJANGO_ID, DJANGO_CT):
            # to ensure the value is serialized correctly.
            if field_name == DJANGO_ID:
                term = int(term)
            term = _term_to_xapian_value(term, field_type)
            return xapian.Query('%s%s' % (TERM_PREFIXES[field_name], term))

        # we construct the query dates in a slightly different way
        if field_type == 'datetime':
            date, time = term.split()
            return xapian.Query(xapian.Query.OP_AND_MAYBE,
                                constructor.format(prefix=prefix, term=date),
                                constructor.format(prefix=prefix, term=time)
                                )

        # only use stem if field is text or "None"
        if field_type not in ('text', None):
            stemmed = False

        unstemmed_term = constructor.format(prefix=prefix, term=term)
        if stemmed:
            stem = xapian.Stem(self.backend.language)
            stemmed_term = 'Z' + constructor.format(prefix=prefix, term=stem(term).decode('utf-8'))

            return xapian.Query(xapian.Query.OP_OR,
                                xapian.Query(stemmed_term),
                                xapian.Query(unstemmed_term)
                                )
        else:
            return xapian.Query(unstemmed_term)
342941
def _sumterm(lexer):
    """"""
    xorterm = _xorterm(lexer)
    sumterm_prime = _sumterm_prime(lexer)
    if sumterm_prime is None:
        return xorterm
    else:
        return ('or', xorterm, sumterm_prime)
18678
def p_term(tok):
        """"""
        if len(tok) == 4:
            tok[0] = MathBinOpRule(tok[2], tok[1], tok[3])
        else:
            tok[0] = tok[1]
153056
function makeWordNet(input_path, preload){


	wn.isVerb = function( str, callback ){
		var word = wn.morphyPromise( str );
		var res = word.then(function(data){
			var posArray = data.pick( "part_of_speech" );
			return posArray.contains( "v" );
		});
		return res.nodeify( callback );
	};

	wn.isNoun = function(str, callback){
		var word = wn.morphyPromise(str);
		var res = word.then(function(data){
		  var posArray = data.pick("part_of_speech");
		  return posArray.contains("n");
		});
		return res.nodeify(callback);
	};

	wn.isAdjective = function(str, callback){
		var word = wn.morphyPromise(str);
		var res = word.then(function(data){
		  var posArray = data.pick("part_of_speech");
		  return posArray.contains("a") || posArray.contains("s");
		});
		return res.nodeify(callback);
	};

	wn.isAdverb = function(str, callback){
		var word = wn.morphyPromise(str);
		var res = word.then(function(data){
		  var posArray = data.pick("part_of_speech");
		  return posArray.contains("r");
		});
		return res.nodeify(callback);
	};

	wn.fetchSynset = function(identifier, callback){
		var ret;
	  var inputs = identifier.split(".");
	  if (!wn.preload){
		  var query = "SELECT s.synsetid AS synsetid, s.definition AS definition, s.pos AS pos, l.lexdomainname AS lexdomain FROM wordsXsensesXsynsets AS s LEFT JOIN lexdomains AS l ON l.lexdomainid = s.lexdomainid ";
		  query += "WHERE s.pos = $pos AND s.lemma = $lemma AND s.sensenum = $sensenum";

		  ret = db.eachAsync(query,{
			$lemma: inputs[0],
			$pos: inputs[1],
			$sensenum: inputs[2]
		   });
	  } else {
		  ret = wn.WORDSxSENSESxSYNSETSxLEXDOMAINS.then(function(d){
			  var search_lemma = inputs[0];
			  var res;
			  var candidateSet = d[search_lemma];
			  for (var i = 0; i < candidateSet.length; i++)
			  {
				  if (candidateSet[i].pos === inputs[1] && candidateSet[i].sensenum === inputs[2]){
					  res = candidateSet[i];
				  }
			  }
			  return res;
		  });
	  }

	   return ret.then(_appendLemmas).then(function(data){
		 return new wn.Synset(data);
	   }).nodeify(callback);
	};

	// Synset Class
	wn.Synset = function(obj){
		  this.synsetid = obj.synsetid;
		  this.words = obj.words;
		  this.definition = obj.definition;
		  this.pos = obj.pos;
		  this.lexdomain = obj.lexdomain;

		  if(obj.hypernym){
			this.hypernym = obj.hypernym;
		  }

		  if(obj.hyponym){
			  this.hyponym = obj.hyponym;
		  }

		  if(obj.holonymOf){
			  this.holonymOf = obj.holonymOf;
		  }

		  if(obj.domain_type){
			  this.domain_type = obj.domain_type;
		  }

		  if(obj.term_type){
			  this.term_type = obj.term_type;
		  }
	};

	wn.Synset.prototype = {
			  constructor: wn.Synset,
			  fetchSynset: function(callback){
				  var inputs = obj.split(".");

				  var query = "SELECT s.synsetid, s.definition, s.pos, l.lexdomainname AS lexdomain FROM wordsXsensesXsynsets AS s LEFT JOIN lexdomains AS l ON l.lexdomainid = s.lexdomainid";
				  query += "WHERE s.pos = $pos AND s.lemma = $lemma AND s.sensenum = $sensenum";

				  var ret = db.eachAsync(query,{
					   $lemma: inputs[0],
					   $pos: inputs[1],
					   $sensenum: inputs[2]
					 });

				  ret.then(function(data){
					  this.synsetid = data.synsetid;
					  this.definition = data.definition;
					  this.pos = data.pos;
					  this.lexdomain = data.lexdomain;

					  callback
				  });

				  fetched = true;
			  },
			  getExamples: function(callback){
				  var promise = _findSamplesArray(this.synsetid).map(function(item){
					return new wn.Example(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getLemmas: function(callback){
				var promise = _findLemmasArray(this.synsetid).map(function(item){
					return new wn.Word(item.lemma);
				});
				return promise.nodeify(callback);
			  },
			  getHypernyms: function(callback){
				  var promise = _findHypernymsArray(this.synsetid).map(_appendLemmas).map(function(item){
					   return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getHypernymsTree: function(callback){
				function getHypernymFromId(input){
					return _findHypernymsArray(input).map(_appendLemmas).map(function(item){
						item.hypernym = getHypernymFromId(item.synsetid);
						return Promise.props(item);
					}).map(function(item){
						var obj = new wn.Synset(item);
						return obj;
					});
				}
				var promise = getHypernymFromId(this.synsetid);
				return promise.nodeify(callback);
			  },
			  getHyponyms: function(callback){
				  var promise = _findHyponymsArray(this.synsetid).map(_appendLemmas).map(function(item){
					   return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getHyponymsTree: function(callback){
				  function getHyponymsFromId(input){
					  return _findHyponymsArray(input).map(_appendLemmas).map(function(item){
						  item.hyponym = getHyponymsFromId(item.synsetid);
						  return Promise.props(item);
					  }).map(function(item){
						 var obj = new wn.Synset(item);
						 return obj;
					  });
				  }
				  var promise = getHyponymsFromId(this.synsetid);
				  return promise.nodeify(callback);
			  },
			  getHolonyms: function(type, callback){
				  var promise = _findHolonymsArray(this.synsetid, type).map(_appendLemmas).map(function(item){
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getMeronyms: function(type, callback){
				  var promise = _findMeronymsArray(this.synsetid, type).map(_appendLemmas).map(function(item){
					 return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getSisterTerms: function(callback){
				  var promise = _findSisterTermsArray(this.synsetid).map(_appendLemmas).map(function(item){
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  causeOf: function(callback){
				  var promise = _findCauseOfArray(this.synsetid).map(_appendLemmas).map(function(item){
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getDomains: function(callback){

				  var classification;

				  function _findDomainsArray(synsetid){
					  var arr;
					  if (!wn.preload){
							var query = "SELECT synset2id, linkid FROM semlinks WHERE synset1id = $synset1id AND linkid IN (91, 93, 95)";
							arr = db.allAsync(query, {
								$synset1id: synsetid
							});
					  } else {
							arr = wn.SEMLINKS.then(function(data){
								return data.filter(function(e){
									return e.synset1id === synsetid && [91,93,95].contains(e.linkid);
								});
							});
					  }

						return arr.map(function(data){
							var obj = {};
							obj.synsetid = data.synset2id;

							switch(data.linkid){
							  case 91:
								classification = "topic";
							  break;
							  case 93:
								classification = "region";
							  break;
							  case 95:
								classification = "usage";
							  break;
							}

							return _findSynsetDefFromId(obj);
						});
					}

				  var promise = _findDomainsArray(this.synsetid).map(_appendLemmas).map(function(item){
					  item.domain_type = classification;
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  getDomainTerms: function(callback){

				  var classification;

				  function _findDomainTermsArray(synsetid){
					  var arr;
					  if (!wn.preload){
							var query = "SELECT synset1id, linkid FROM semlinks WHERE synset2id = $synset2id AND linkid IN (92, 94, 96)";
							arr = db.allAsync(query, {
								$synset2id: synsetid
							});
						} else {
							arr = wn.SEMLINKS.then(function(data){
								return data.filter(function(e){
									return e.synset2id === synsetid && [92,94,96].contains(e.linkid);
								});
							});
						}

						return arr.map(function(data){
							var obj = {};
							obj.synsetid = data.synset1id;
							switch(data.linkid){
							  case 92:
								classification = "topic";
							  break;
							  case 94:
								classification = "region";
							  break;
							  case 96:
								classification = "usage";
							  break;
							}

						return _findSynsetDefFromId(obj);
		  });
					}

				  var promise = _findDomainTermsArray(this.synsetid).map(_appendLemmas).map(function(item){
					  item.term_type = classification;
					  return new wn.Synset(item);
				  });
				  return promise.nodeify(callback);
			  },
			  toString: function(){
				  return this.definition;
			  },
			};

	// Example Class
	wn.Example = function(obj){
		this.synsetid = obj.synsetid;
		this.sampleid = obj.sampleid;
		this.sample = obj.sample;
	};

	wn.Example.prototype = {
			constructor: wn.Example,
			toString: function(){
				return this.sample;
			}
	};

	wn.print = function(obj){
		switch(obj.constructor){
		case Array:
			for (var i = 0; i < obj.length; i++){
				wn.print(obj[i]);
			}
		break;
		case wn.Synset:
			var synsetString = getSynsetString(obj, 0);
			console.log(synsetString);
		break;
		case wn.Word:
			console.log("L: " + obj.lemma);
		break;
		case wn.Example:
			console.log("E: " + obj.sample);
		break;
		}
	};

	function _findSisterTermsArray(synsetid){
		var hypernymIdArray = _findHypernymsArray(synsetid);
		return hypernymIdArray.map(function(data){
			var arr;
			if (!wn.preload){
				var query = "SELECT synset1id FROM semlinks WHERE synset2id = $synset2id AND linkid = 1";
				arr =  db.allAsync(query,{
					$synset2id: data.synsetid
				});
			} else {
				arr = wn.SEMLINKS.SISTERS.then(function(resultSet){
					return resultSet[data.synsetid] || [];
				});			}
			arr = arr.map(function(data){
				var obj = {};
				obj.synsetid = data.synset1id;
				return _findSynsetDefFromId(obj);
			}).map(_appendLemmas);
			var ret = data;
			ret.hyponym = arr;
			return Promise.props(ret);
		});
	}

	function _findHyponymsArray(synsetid){
		var arr;
		if (!wn.preload){
			var query = "SELECT synset2id FROM semlinks WHERE synset1id = $synset1id AND linkid = 2";
			 arr =  db.allAsync(query,{
				$synset1id: synsetid
			});
		} else {
			arr = wn.SEMLINKS.filter(function(e){
				return e.synset1id === synsetid && e.linkid === 1;
			});
		}

		return arr.map(function(data){
			var obj = {};
			obj.synsetid = data.synset2id;
			return _findSynsetDefFromId(obj);
		});
	}

	function _findCauseOfArray(synsetid){
		var arr;
		if (!wn.preload){
			var query = "SELECT synset2id FROM semlinks WHERE synset1id = $synset1id AND linkid = 23";
			arr = db.allAsync(query, {
			$synset1id: synsetid
		});
		} else {
			arr = wn.SEMLINKS.filter(function(e){
				return e.linkid === 23 && e.synset1id === synsetid;
			});
		}
		return arr.map(function(data){
			var obj = {};
			obj.synsetid = data.synset2id;
			return _findSynsetDefFromId(obj);
		});
	}

	function _appendLemmas(data){
		var promise = _findLemmasArray(data.synsetid).map(function(item){
			return new wn.Word(item.lemma);
		});
		var ret = data;
		ret.words = promise;
		return Promise.props(ret);
	}

	function _findHolonymsArray(synsetid, type){
		/*
		linkids are:
		part: 11
		member: 13
		substance: 15
		*/
		var ids;
		var linkid;
		var arr;

		if(type){
		  type = Array.isArray(type) ? type : new Array(type);
		  ids = type.map(function(elem){
			switch (elem) {
			case "part" : return 11;
			case "member" : return 13;
			case "substance" : return 15;
			}
		  });
		  linkid = "IN (" + ids.join(",") + ")";
		} else {
		  linkid = "IN (11,13,15)";
		}
		if (!wn.preload){
			var query = "SELECT synset1id FROM semlinks WHERE synset2id = $synset2id AND linkid " + linkid;
			arr = db.allAsync(query, {
				$synset2id: synsetid
			});
		}
		else {
			arr = wn.SEMLINKS.then(function(data){
				var ret = data.filter(function(e){
					if (type){
						return e.synset2id === synsetid && ids.contains(e.linkid);
					} else {
						return e.synset2id === synsetid;
					}
				});
				return ret;
			});
		}
		return arr.map(function(data){
			var obj = {};
			obj.synsetid = data.synset1id;
			return _findSynsetDefFromId(obj);
		});
	}

	function _findMeronymsArray(synsetid, type){
		/*
		linkids are:
		part: 12
		member: 14
		substance: 16
		*/
		var synID = synsetid;
		var linkid;
		if(type){
		  type = Array.isArray(type) ? type : new Array(type);
		  var ids = type.map(function(elem){
			  switch (elem) {
			  case "part" : return 12;
			  case "member" : return 14;
			  case "substance" : return 16;
			  }
		  });
		  linkid = "IN (" + ids.join(",") + ")";
		} else {
		  linkid = "IN (12,14,16)";
		}

		var arr;
		if(!wn.preload){
			var query = "SELECT synset1id FROM semlinks WHERE synset2id = $synset2id AND linkid " + linkid;
			arr = db.allAsync(query, {
				$synset2id: synID
			});
		} else {
			arr = wn.SEMLINKS.then(function(data){
				var ret = data.filter(function(e){
					return e.synset2id === synsetid && ids.contains(e.linkid);
				});
				return ret;
			});
		}
		return arr.map(function(data){
			var obj = {};
			obj.synsetid = data.synset1id;
			return _findSynsetDefFromId(obj);
		});
	}

	function _findHypernymsArray(synsetid){
		var arr;
		if (!wn.preload){
			var query = "SELECT synset2id FROM semlinks WHERE synset1id = $synset1id AND linkid = 1";
			arr =  db.allAsync(query,{
				$synset1id: synsetid
			});
		} else {
			arr = wn.SEMLINKS.HYPERNYMS.then(function(e){
				return e[synsetid] || [];
			});
		}
		var ret = arr.map(function(d){
			var obj = {};
			obj.synsetid = d.synset2id;
			return _findSynsetDefFromId(obj);
		});
		return ret;
	}

	function _findSamplesArray(synsetid){
		if(!wn.preload){
	  var query = "SELECT * FROM samples WHERE synsetid = $synsetid";
	  return db.allAsync(query,{
		  $synsetid: synsetid
	  });
		}
		else {
			var ret = wn.SAMPLES.then(function(d){
				return d[synsetid];
			});
			return ret;
		}
	}

	function _findLemmasArray(synsetid){
		var query = "SELECT words.lemma FROM words INNER JOIN senses ON words.wordid = senses.wordid WHERE senses.synsetid = $synsetid";
		return db.allAsync(query,{
			$synsetid: synsetid
		});
	}

	function _formSynsetsArray(data){
	  var SynsetArray = [];
	  for (var i = 0; i < data.length; i++){
		var obj =  _findSynsetDefFromId(data[i]);
		SynsetArray.push(obj);
	  }
	  return Promise.all(SynsetArray);
	}

	function _findSynsetDefFromId( data ) {
		var ret;
		if ( !wn.preload ) {
			var query = "SELECT ss.synsetid, ss.pos, ld.lexdomainname AS lexdomain, ss.definition";
			query += " FROM synsets AS ss INNER JOIN lexdomains AS ld ON ld.lexdomainid = ss.lexdomainid";
			query += " WHERE synsetid = $synsetid";
			ret = db.eachAsync( query, {
				$synsetid: data.synsetid
			});
		} else {
			ret = wn.SYNSETSxLEXDOMAINS.then( function( returnSet ) {
				return returnSet[data.synsetid];
			});
		}
		return ret;
	}

	return wn;
}
1195988
def OneHot0(*xs, simplify=True, conj=True):
    
    xs = [Expression.box(x).node for x in xs]
    terms = list()
    if conj:
        for x0, x1 in itertools.combinations(xs, 2):
            terms.append(exprnode.or_(exprnode.not_(x0),
                                      exprnode.not_(x1)))
        y = exprnode.and_(*terms)
    else:
        for _xs in itertools.combinations(xs, len(xs) - 1):
            terms.append(exprnode.and_(*[exprnode.not_(x) for x in _xs]))
        y = exprnode.or_(*terms)
    if simplify:
        y = y.simplify()
    return _expr(y)
224123
def _call(self, x):
        """"""
        result = self.sess.run(self.output_tensor,
                               feed_dict={self.input_tensor: np.asarray(x)})

        return result
168703
def setup_data_split(X, y, tokenizer, proc_data_dir, **kwargs):
    
    X_train, X_val, X_test, y_train, y_val, y_test = split_data(X, y)

    # only build vocabulary on training data
    tokenizer.build_vocab(X_train)

    process_save(X_train, y_train, tokenizer, path.join(
        proc_data_dir, 'train.bin'), train=True, **kwargs)
    process_save(X_val, y_val, tokenizer, path.join(
        proc_data_dir, 'val.bin'), **kwargs)
    process_save(X_test, y_test, tokenizer, path.join(
        proc_data_dir, 'test.bin'), **kwargs)
506968
def _phrase_query(self, term_list, field_name, field_type):
        
        term_list = [self._term_query(term, field_name, field_type,
                                      stemmed=False) for term in term_list]

        query = xapian.Query(xapian.Query.OP_PHRASE, term_list)
        return query
510291
def handle_term(self, _, __, tokens: ParseResults) -> ParseResults:
        """"""
        self.ensure_node(tokens)
        return tokens
307687
function createXprop() {
    if( 0 >= count( $this->xprop ))
      return;
    $xprop = null;
    foreach( $this->xprop as $label => $xpropPart ) {
      $attributes = $this->_createParams( $xpropPart['params'], array( 'LANGUAGE' ));
      if( is_array( $xpropPart['value'] )) {
        foreach( $xpropPart['value'] as $pix => $theXpart )
          $xpropPart['value'][$pix] = $this->_strrep( $theXpart );
        $xpropPart['value']  = implode( ',', $xpropPart['value'] );
      }
      else
        $xpropPart['value'] = $this->_strrep( $xpropPart['value'] );
      $xprop .= $this->_createElement( strtoupper( $label ), $attributes, $xpropPart['value'] );
    }
    return $xprop;
  }
1056544
def create(cls, schema, name):
        
        fn = cls.tags.get(name, XBuiltin)
        return fn(schema, name)
515501
def xyzlim(vmin, vmax=None):
    """"""
    if vmax is None:
        vmin, vmax = -vmin, vmin
    xlim(vmin, vmax)
    ylim(vmin, vmax)
    zlim(vmin, vmax)
424250
def _build_label_filter(category, *args, **kwargs):
    """"""
    terms = list(args)
    for key, value in six.iteritems(kwargs):
        if value is None:
            continue

        suffix = None
        if key.endswith(
            ("_prefix", "_suffix", "_greater", "_greaterequal", "_less", "_lessequal")
        ):
            key, suffix = key.rsplit("_", 1)

        if category == "resource" and key == "resource_type":
            key = "resource.type"
        else:
            key = ".".join((category, "label", key))

        if suffix == "prefix":
            term = '{key} = starts_with("{value}")'
        elif suffix == "suffix":
            term = '{key} = ends_with("{value}")'
        elif suffix == "greater":
            term = "{key} > {value}"
        elif suffix == "greaterequal":
            term = "{key} >= {value}"
        elif suffix == "less":
            term = "{key} < {value}"
        elif suffix == "lessequal":
            term = "{key} <= {value}"
        else:
            term = '{key} = "{value}"'

        terms.append(term.format(key=key, value=value))

    return " AND ".join(sorted(terms))
1265283
def _buildTerms(self):
        
        termLons = tables.termLons(tables.EGYPTIAN_TERMS)
        res = {}
        for (ID, sign, lon) in termLons:
            try:
                res[sign][ID] = lon
            except KeyError:
                res[sign] = {}
                res[sign][ID] = lon
        return res
1309659
def _from_xapian_value(value, field_type):
    
    assert field_type in FIELD_TYPES
    if field_type == 'boolean':
        if value == 't':
            return True
        elif value == 'f':
            return False
        else:
            InvalidIndexError('Field type "%d" does not accept value "%s"' % (field_type, value))
    elif field_type == 'integer':
        return int(value)
    elif field_type == 'float':
        return xapian.sortable_unserialise(value)
    elif field_type == 'date' or field_type == 'datetime':
        datetime_value = datetime.datetime.strptime(value, DATETIME_FORMAT)
        if field_type == 'datetime':
            return datetime_value
        else:
            return datetime_value.date()
    else:  # field_type == 'text'
        return value