Extract property value from record using the given urn search filter.
426079
def _parse_prop(search, proplist):
    """"""
    props = [i for i in proplist if all(item in i['urn'].items() for item in search.items())]
    if len(props) > 0:
        return props[0]['value'][list(props[0]['value'].keys())[0]]
1272867
def extract_entity(found):
    """"""
    obj = dict()
    for prop in found.entity.property:
        obj[prop.name] = prop.value.string_value
    return obj
372315
private RecordSelector parseRecordSelector(String recordSelectorString) throws Exception {
		if (null == recordSelectorString || "" == recordSelectorString) {
			return null;
		}
		
		{
			Matcher matcher = patternSearchString.matcher(recordSelectorString);
			if( matcher.matches() ) {
				String[] fieldNames = matcher.group(1).split(",");
				String searchString = matcher.group(2);
				return new RecordSelectorSearchString(fieldNames, searchString);
			}
		}
		
		// EQ
		{
			Matcher matcher = patternEq.matcher(recordSelectorString);
			if( matcher.matches() ) {
				return new RecordSelectorComparison(
					matcher.group(1)
					,RecordSelectorComparison.Comparison.EQUAL
					,matcher.group(2)
					);
			}
		}
		
		// NE
		{
			Matcher matcher = patternNe.matcher(recordSelectorString);
			if( matcher.matches() ) {
				return new RecordSelectorComparison(
					matcher.group(1)
					,RecordSelectorComparison.Comparison.NOT_EQUAL
					,matcher.group(2)
					);
			}
		}
		
		// GT
		{
			Matcher matcher = patternGt.matcher(recordSelectorString);
			if( matcher.matches() ) {
				return new RecordSelectorComparison(
					matcher.group(1)
					,RecordSelectorComparison.Comparison.GREATER_THAN
					,matcher.group(2)
					);
			}
		}
		
		// GE
		{
			Matcher matcher = patternGe.matcher(recordSelectorString);
			if( matcher.matches() ) {
				return new RecordSelectorComparison(
					matcher.group(1)
					,RecordSelectorComparison.Comparison.GREATER_THAN_OR_EQUAL
					,matcher.group(2)
					);
			}
		}
		
		// LT
		{
			Matcher matcher = patternLt.matcher(recordSelectorString);
			if( matcher.matches() ) {
				return new RecordSelectorComparison(
					matcher.group(1)
					,RecordSelectorComparison.Comparison.LESS_THAN
					,matcher.group(2)
					);
			}
		}
		
		// LE
		{
			Matcher matcher = patternLe.matcher(recordSelectorString);
			if( matcher.matches() ) {
				return new RecordSelectorComparison(
					matcher.group(1)
					,RecordSelectorComparison.Comparison.LESS_THAN_OR_EQUAL
					,matcher.group(2)
					);
			}
		}
		
		// NULL
		{
			Matcher matcher = patternNull.matcher(recordSelectorString);
			if( matcher.matches() ) {
				return new RecordSelectorComparison(
					matcher.group(1)
					,RecordSelectorComparison.Comparison.IS_NULL
					,(Expression)null
					);
			}
		}
		
		// NOT NULL
		{
			Matcher matcher = patternNotNull.matcher(recordSelectorString);
			if( matcher.matches() ) {
				return new RecordSelectorComparison(
					matcher.group(1)
					,RecordSelectorComparison.Comparison.IS_NOT_NULL
					,(Expression)null
					);
			}
		}

		throw new Exception("Invalid query : can not parse record selector: "+recordSelectorString);
	}
415651
private List<Object> getValues(PivotField field, Map<Integer, Object> filter) {
//		long start = System.currentTimeMillis();
		List<Object> values = new ArrayList<Object>();
		int fieldIndex = field.getIndex();
		for (int i = 0; i < dataSource.getRowCount(); i++) {
			if (filter.isEmpty()) {
				values.add(dataSource.getValueAt(i, fieldIndex));
			} else {
				if (acceptValue(i, filter)) {
					values.add(dataSource.getValueAt(i, fieldIndex));
				}
			}
		}
//		long stop = System.currentTimeMillis();
//		System.out.println("getValues in " + (stop - start));
		
		return values;
	}
1027882
Filter getFilterProperty(String name, Filter defaultValue) {
        String val = getProperty(name);
        try {
            if (val != null) {
                return (Filter) getClassInstance(val).newInstance();
            }
        } catch (Exception ex) {
            // We got one of a variety of exceptions in creating the
            // class or creating an instance.
            // Drop through.
        }
        // We got an exception.  Return the defaultValue.
        return defaultValue;
    }
456277
def get_by_uri(cls, uri):
        """"""
        assert uri is not None
        return cls.query.filter_by(uri=uri).one_or_none()
485319
private <T> SearchResultsBean<T> find(SearchCriteriaBean criteria, String type,
            IUnmarshaller<T> unmarshaller) throws StorageException {
        try {
            SearchResultsBean<T> rval = new SearchResultsBean<>();

            // Set some default in the case that paging information was not included in the request.
            PagingBean paging = criteria.getPaging();
            if (paging == null) {
                paging = new PagingBean();
                paging.setPage(1);
                paging.setPageSize(20);
            }
            int page = paging.getPage();
            int pageSize = paging.getPageSize();
            int start = (page - 1) * pageSize;

            SearchSourceBuilder builder = new SearchSourceBuilder().size(pageSize).from(start).fetchSource(true);

            // Sort order
            OrderByBean orderBy = criteria.getOrderBy();
            if (orderBy != null) {
                String name = orderBy.getName();
                if (name.equals("name") || name.equals("fullName")) { //$NON-NLS-1$ //$NON-NLS-2$
                    name += ".raw"; //$NON-NLS-1$
                }
                if (orderBy.isAscending()) {
                    builder.sort(name, SortOrder.ASC);
                } else {
                    builder.sort(name, SortOrder.DESC);
                }
            }

            // Now process the filter criteria
            List<SearchCriteriaFilterBean> filters = criteria.getFilters();

            QueryBuilder q = null;

            if (filters != null && !filters.isEmpty()) {
                FilterBuilder andFilter = FilterBuilders.filter();
                int filterCount = 0;
                for (SearchCriteriaFilterBean filter : filters) {
                    String propertyName = filter.getName();
                    if (filter.getOperator() == SearchCriteriaFilterOperator.eq) {
                        andFilter.add(FilterBuilders.termFilter(propertyName, filter.getValue()));
                        filterCount++;
                    } else if (filter.getOperator() == SearchCriteriaFilterOperator.like) {
                        q = QueryBuilders.wildcardQuery(propertyName, filter.getValue().toLowerCase().replace('%', '*'));
                    } else if (filter.getOperator() == SearchCriteriaFilterOperator.bool_eq) {
                        andFilter.add(FilterBuilders.termFilter(propertyName, "true".equals(filter.getValue()))); //$NON-NLS-1$
                        filterCount++;
                    }
                    // TODO implement the other filter operators here!
                }

                if (filterCount > 0) {
                    q = FilterBuilders.boolFilter(andFilter);
                }
            }
            builder.query(q);

            String query = builder.string();
            Search search = new Search.Builder(query)
                    .addIndex(getIndexName())
                    .addType(type)
                    .build();
            SearchResult response = esClient.execute(search);
            @SuppressWarnings({ "unchecked", "rawtypes" })
            List<Hit<Map<String, Object>, Void>> thehits = (List) response.getHits(Map.class);

            rval.setTotalSize((int)(long)response.getTotal());
            for (Hit<Map<String,Object>,Void> hit : thehits) {
                Map<String, Object> sourceAsMap = hit.source;
                T bean = unmarshaller.unmarshal(sourceAsMap);
                rval.getBeans().add(bean);
            }
            return rval;
        } catch (Exception e) {
            throw new StorageException(e);
        }
    }
932208
function (record) {
      var recordToSend = { object: record };

      recordToSend.columnValues = this.getRecordColumnValues(record);
      recordToSend.searchKeywords = this.getRecordKeywords(record);
      recordToSend.filterValues = this.getRecordFilterValues(record);
      recordToSend.color = this.getRecordColor(record);

      return recordToSend;
    }
103236
private static String extractTopItem(String searchString, String schema, int startIdx) {
		String extracted = null;
		int propIdx = schema.indexOf("\"properties\"", startIdx);
		if (propIdx == -1) {
			propIdx = Integer.MAX_VALUE;
		}
		// check for second
		int idIdx = schema.indexOf("\"" + searchString + "\"", startIdx);
		int secondIdIdx = schema.indexOf("\"" + searchString + "\"", idIdx + 1);
		if (secondIdIdx != -1 && propIdx > secondIdIdx) {
			idIdx = secondIdIdx;
		}
		if (idIdx != -1 && propIdx > idIdx) { // make sure we're not in a nested
												// id
			// find the 1st and second " after the idx
			int valueStartIdx = schema.indexOf("\"", idIdx + (searchString.length() + 2));
			int valueEndIdx = schema.indexOf("\"", valueStartIdx + 1);
			extracted = schema.substring(valueStartIdx + 1, valueEndIdx);
		}
		return extracted;
	}
531825
function pickBy(object, predicate) {
    return Object.keys(object).reduce(function (records, key) {
        var value = object[key];
        if (predicate(value, key)) {
            records[key] = value;
        }
        return records;
    }, {});
}
631279
def search_url(obj, url_data, pageno, seen_objs):
    """"""
    if isinstance(obj, PDFObjRef):
        if obj.objid in seen_objs:
            # prevent recursive loops
            return
        seen_objs.add(obj.objid)
        obj = obj.resolve()
    if isinstance(obj, dict):
        for key, value in obj.items():
            if key == 'URI' and isinstance(value, basestring):
                # URIs should be 7bit ASCII encoded, but be safe and encode
                # to unicode
                # XXX this does not use an optional specified base URL
                url = strformat.unicode_safe(value)
                url_data.add_url(url, page=pageno)
            else:
                search_url(value, url_data, pageno, seen_objs)
    elif isinstance(obj, list):
        for elem in obj:
            search_url(elem, url_data, pageno, seen_objs)
    elif isinstance(obj, PDFStream):
        search_url(obj.attrs, url_data, pageno, seen_objs)
331196
def get_by_string(cls, fields, query):
	''''''
	try: pk = int(query)
	except ValueError: pass
	else: return cls.objects.get(pk=pk)
	obj = list(cls.objects.filter(reduce( op.or_,
		list(Q(**{'{}__icontains'.format(f): query}) for f in fields) )))
	if len(obj) > 1:
		raise cls.MultipleObjectsReturned((
			u'Unable to uniquely identify {}'
				' by provided criteria: {!r} (candidates: {})' )\
			.format(cls.__name__, query, ', '.join(it.imap(unicode, obj))) )
	elif not len(obj):
		raise cls.DoesNotExist(
			u'Unable to find site by provided criteria: {!r}'.format(query) )
	return obj[0]
607421
def filter(cls, start_position="", max_results="", qb=None, **kwargs):
        
        return cls.where(build_where_clause(**kwargs),
                         start_position=start_position, max_results=max_results, qb=qb)
894329
@Nullable
    private Record getRecord(final URI layer, @Nullable final URI id) throws Throwable {
        final Record record = id == null ? null : getSession().retrieve(layer).ids(id).exec()
                .getUnique();
        if (record != null && layer.equals(KS.MENTION)) {
            final String template = "SELECT ?e WHERE { ?e $$ $$ "
                    + (getUIConfig().isDenotedByAllowsGraphs() ? ""
                            : "FILTER NOT EXISTS { GRAPH ?e { ?s ?p ?o } } ") + "}";
            for (final URI entityID : getSession()
                    .sparql(template, getUIConfig().getDenotedByProperty(), id).execTuples()
                    .transform(URI.class, true, "e")) {
                record.add(KS.REFERS_TO, entityID);
            }
        }
        return record;
    }
401663
private Object getValue(PageContext pc, SQL sql, Query querySource, int row, Collection.Key key, Object value) throws PageException {
	if (value instanceof ZSelectItem) return executeExp(pc, sql, querySource, ((ZSelectItem) value).getExpression(), row);
	return querySource.getAt(key, row);
    }
1326204
private Object getRawValue(String columnName, Map<String, Object> content)
            throws ColumnNotFoundException {
        String field = columnName;
        Object value = content;

        while (field != null) {
            // If at any point in the path a null is encountered stop
            if (value == null) {
                throw new ColumnNotFoundException();
            }

            // With the exception of leaf values the intermediate values must always be Maps.
            if (!(value instanceof Map)) {
                throw new ColumnNotFoundException();
            }

            //noinspection unchecked
            Map<String, Object> map = (Map<String, Object>) value;
            String nextField = null;

            int separator = field.indexOf('/');
            if (separator != -1) {
                nextField = field.substring(separator + 1);
                field = field.substring(0, separator);
            }

            // Typically Hive column names are all lower case.  Because of this we can't just look up the key directly;
            // we need to look it up in a case-insensitive fashion.  For efficiency first try it as-is.

            boolean found = false;
            if (map.containsKey(field)) {
                value = map.get(field);
                found = true;
            } else {
                // Look for the key case-insensitively
                for (Iterator<String> iter = map.keySet().iterator(); !found && iter.hasNext(); ) {
                    String key = iter.next();
                    if (key.equalsIgnoreCase(field)) {
                        value = map.get(key);
                        found = true;
                    }
                }
            }
            if (!found) {
                throw new ColumnNotFoundException();
            }

            field = nextField;
        }

        return value;
    }
762627
@SuppressWarnings("unchecked")
    private static Object getIndexedValue(Object obj, Property property, int index, ObjectWrapper options) {
        if (property == null) {
            throw new IllegalArgumentException("Cannot get the indexed value from 'null' property.");
        }

        Object propertyValue = property.get(obj);

        if (propertyValue == null) {
            throw new NullPointerException("Invalid 'null' value found for indexed '" + property + "' in "
                                                   + obj.getClass().getName() + ".");

        }

        if (propertyValue instanceof List) {
            List list = (List) propertyValue;
            int size = list.size();

            if (size < index) {
                if (options.isOutOfBoundsSafety) {
                    return null;
                } else {
                    throw new IndexOutOfBoundsException("The indexed " + property + " in "
                                                                + obj.getClass().getSimpleName() + " object has only '" + size + "' elements," +
                                                                " but index '" + index + "' requested.");
                }
            }

            return list.get(index);
        } else if (propertyValue.getClass().isArray()) {
            int lenght = Array.getLength(propertyValue);

            if (lenght < index && options.isOutOfBoundsSafety) {
                return null;
            }

            try {
                return Array.get(propertyValue, index);
            } catch (ArrayIndexOutOfBoundsException e) {
                throw new IndexOutOfBoundsException("The indexed " + property + " in "
                                                            + obj.getClass().getSimpleName() + " object has only '" + lenght + "' elements," +
                                                            " but index '" + index + "' requested.");

            }
        } else if (propertyValue instanceof Iterable) {
            Iterable iterable = (Iterable) propertyValue;

            int k = 0;
            for (Object object : iterable) {
                if (k == index) {
                    return object;
                }

                k++;// Hopefully not an infinite iteration
            }

            // Nothing found
            if (options.isOutOfBoundsSafety) {
                return null;
            } else {
                throw new IndexOutOfBoundsException("The indexed " + property + " in "
                                                            + obj.getClass().getSimpleName() + " object has less than '" + index + "'" +
                                                            " elements.");
            }
        } else {
            throw new IllegalArgumentException("Cannot get an indexed value from the not indexed " + property
                                                       + ". Only List, array and Iterable types are supported, but " + property.getType().getSimpleName()
                                                       + " found.");
        }
    }