Build a function for testing data associated with the node in the graph.

    :param key: The node data dictionary key to check
    :param data_predicate: The filter to apply to the node data dictionary
489168
def build_node_graph_data_search(key: str, data_predicate: Callable[[Any], bool]):  # noqa: D202
    

    def node_data_filter(graph: BELGraph, node: BaseEntity) -> bool:
        """Pass if the given node has a given data annotated and passes the contained filter."""
        value = graph.nodes[node].get(key)
        return value is not None and data_predicate(value)

    return node_data_filter
1334604
def _annotation_dict_any_filter(edge_data: EdgeData, query: Mapping[str, Iterable[str]]) -> bool:
    
    annotations = edge_data.get(ANNOTATIONS)

    if annotations is None:
        return False

    return any(
        key in annotations and value in annotations[key]
        for key, values in query.items()
        for value in values
    )
821279
def check_taxonomy(taxonomy):
    
    current_app.logger.info(
        "Building graph with Python RDFLib version %s" %
        rdflib.__version__
    )

    store = rdflib.ConjunctiveGraph()
    store.parse(taxonomy)

    current_app.logger.info("Graph was successfully built.")

    prefLabel = "prefLabel"
    hiddenLabel = "hiddenLabel"
    altLabel = "altLabel"
    composite = "composite"
    compositeOf = "compositeOf"
    note = "note"

    both_skw_and_ckw = []

    # Build a dictionary we will reason on later.
    uniq_subjects = {}
    for subject in store.subjects():
        uniq_subjects[subject] = None

    subjects = {}
    for subject in uniq_subjects:
        strsubject = str(subject).split("#Composite.")[-1]
        strsubject = strsubject.split("#")[-1]
        if (strsubject == "http://cern.ch/thesauri/HEPontology.rdf" or
                strsubject == "compositeOf"):
            continue
        components = {}
        for predicate, value in store.predicate_objects(subject):
            strpredicate = str(predicate).split("#")[-1]
            strobject = str(value).split("#Composite.")[-1]
            strobject = strobject.split("#")[-1]
            components.setdefault(strpredicate, []).append(strobject)
        if strsubject in subjects:
            both_skw_and_ckw.append(strsubject)
        else:
            subjects[strsubject] = components

    current_app.logger.info("Taxonomy contains %s concepts." % len(subjects))

    no_prefLabel = []
    multiple_prefLabels = []
    bad_notes = []
    # Subjects with no composite or compositeOf predicate
    lonely = []
    both_composites = []
    bad_hidden_labels = {}
    bad_alt_labels = {}
    # Problems with composite keywords
    composite_problem1 = []
    composite_problem2 = []
    composite_problem3 = []
    composite_problem4 = {}
    composite_problem5 = []
    composite_problem6 = []

    stemming_collisions = []
    interconcept_collisions = {}

    for subject, predicates in iteritems(subjects):
        # No prefLabel or multiple prefLabels
        try:
            if len(predicates[prefLabel]) > 1:
                multiple_prefLabels.append(subject)
        except KeyError:
            no_prefLabel.append(subject)

        # Lonely and both composites.
        if composite not in predicates and compositeOf not in predicates:
            lonely.append(subject)
        elif composite in predicates and compositeOf in predicates:
            both_composites.append(subject)

        # Multiple or bad notes
        if note in predicates:
            bad_notes += [(subject, n) for n in predicates[note]
                          if n not in ('nostandalone', 'core')]

        # Bad hidden labels
        if hiddenLabel in predicates:
            for lbl in predicates[hiddenLabel]:
                if lbl.startswith("/") ^ lbl.endswith("/"):
                    bad_hidden_labels.setdefault(subject, []).append(lbl)

        # Bad alt labels
        if altLabel in predicates:
            for lbl in predicates[altLabel]:
                if len(re.findall("/", lbl)) >= 2 or ":" in lbl:
                    bad_alt_labels.setdefault(subject, []).append(lbl)

        # Check composite
        if composite in predicates:
            for ckw in predicates[composite]:
                if ckw in subjects:
                    if compositeOf in subjects[ckw]:
                        if subject not in subjects[ckw][compositeOf]:
                            composite_problem3.append((subject, ckw))
                    else:
                        if ckw not in both_skw_and_ckw:
                            composite_problem2.append((subject, ckw))
                else:
                    composite_problem1.append((subject, ckw))

        # Check compositeOf
        if compositeOf in predicates:
            for skw in predicates[compositeOf]:
                if skw in subjects:
                    if composite in subjects[skw]:
                        if subject not in subjects[skw][composite]:
                            composite_problem6.append((subject, skw))
                    else:
                        if skw not in both_skw_and_ckw:
                            composite_problem5.append((subject, skw))
                else:
                    composite_problem4.setdefault(skw, []).append(subject)

        # Check for stemmed labels
        if compositeOf in predicates:
            labels = (altLabel, hiddenLabel)
        else:
            labels = (prefLabel, altLabel, hiddenLabel)

        patterns = {}
        for label in [lbl for lbl in labels if lbl in predicates]:
            for expression in [expr for expr in predicates[label]
                               if not _is_regex(expr)]:
                pattern = _get_regex_pattern(expression)
                interconcept_collisions.setdefault(pattern, []).\
                    append((subject, label))
                if pattern in patterns:
                    stemming_collisions.append(
                        (subject,
                         patterns[pattern],
                         (label, expression)
                         )
                    )
                else:
                    patterns[pattern] = (label, expression)

    print("\n==== ERRORS ====")

    if no_prefLabel:
        print("\nConcepts with no prefLabel: %d" % len(no_prefLabel))
        print("\n".join(["   %s" % subj for subj in no_prefLabel]))
    if multiple_prefLabels:
        print(("\nConcepts with multiple prefLabels: %d" %
               len(multiple_prefLabels)))
        print("\n".join(["   %s" % subj for subj in multiple_prefLabels]))
    if both_composites:
        print(("\nConcepts with both composite properties: %d" %
               len(both_composites)))
        print("\n".join(["   %s" % subj for subj in both_composites]))
    if bad_hidden_labels:
        print("\nConcepts with bad hidden labels: %d" % len(bad_hidden_labels))
        for kw, lbls in iteritems(bad_hidden_labels):
            print("   %s:" % kw)
            print("\n".join(["      '%s'" % lbl for lbl in lbls]))
    if bad_alt_labels:
        print("\nConcepts with bad alt labels: %d" % len(bad_alt_labels))
        for kw, lbls in iteritems(bad_alt_labels):
            print("   %s:" % kw)
            print("\n".join(["      '%s'" % lbl for lbl in lbls]))
    if both_skw_and_ckw:
        print(("\nKeywords that are both skw and ckw: %d" %
               len(both_skw_and_ckw)))
        print("\n".join(["   %s" % subj for subj in both_skw_and_ckw]))

    print()

    if composite_problem1:
        print("\n".join(["SKW '%s' references an unexisting CKW '%s'." %
                         (skw, ckw) for skw, ckw in composite_problem1]))
    if composite_problem2:
        print("\n".join(["SKW '%s' references a SKW '%s'." %
                         (skw, ckw) for skw, ckw in composite_problem2]))
    if composite_problem3:
        print("\n".join(["SKW '%s' is not composite of CKW '%s'." %
                         (skw, ckw) for skw, ckw in composite_problem3]))
    if composite_problem4:
        for skw, ckws in iteritems(composite_problem4):
            print("SKW '%s' does not exist but is " "referenced by:" % skw)
            print("\n".join(["    %s" % ckw for ckw in ckws]))
    if composite_problem5:
        print("\n".join(["CKW '%s' references a CKW '%s'." % kw
                         for kw in composite_problem5]))
    if composite_problem6:
        print("\n".join(["CKW '%s' is not composed by SKW '%s'." % kw
                         for kw in composite_problem6]))

    print("\n==== WARNINGS ====")

    if bad_notes:
        print(("\nConcepts with bad notes: %d" % len(bad_notes)))
        print("\n".join(["   '%s': '%s'" % _note for _note in bad_notes]))
    if stemming_collisions:
        print("\nFollowing keywords have unnecessary labels that have "
              "already been generated by Classifier.")
        for subj in stemming_collisions:
            print("   %s:\n     %s\n     and %s" % subj)

    print("\nFinished.")
    sys.exit(0)
1046244
function resolvePrimaryKey(attrNode, context) {
    const errorContext = context.errorContext;
    context.errorContext = ' in primaryKey' + errorContext;

    const neededDataSources = [];

    Object.keys(attrNode.dataSources).forEach(dataSourceName => {
        if (attrNode.dataSources[dataSourceName].joinParentKey) return;
        neededDataSources.push(dataSourceName);
    });

    attrNode.resolvedPrimaryKey = resolveKey(
        attrNode.primaryKey,
        attrNode,
        {
            neededDataSources,
            allowMultiValued: false
        },
        context
    );

    // enable "equal" filter:
    attrNode.primaryKey.forEach(primaryKeyAttrPath => {
        const primaryKeyAttrNode = getLocalAttribute(primaryKeyAttrPath, attrNode, context);

        if (!primaryKeyAttrNode.filter && attrNode.primaryKey.length === 1) {
            if (!primaryKeyAttrNode.hidden) {
                primaryKeyAttrNode.filter = ['equal'];
            }
        }
    });

    context.errorContext = errorContext;
}
804720
def filteritems(predicate, dict_):
    
    predicate = all if predicate is None else ensure_callable(predicate)
    ensure_mapping(dict_)
    return dict_.__class__(ifilter(predicate, iteritems(dict_)))
1373024
def validate(data, schema, defined_keys=False):
    
    if isinstance(data, dict):
        validator = Validator(data, schema, defined_keys=defined_keys)
        validator.validate()
    else:
        raise TypeError('expected data to be of type dict, but got: %s' % type(data))
1195888
def build_upstream_edge_predicate(nodes: Iterable[BaseEntity]) -> EdgePredicate:
    """"""
    nodes = set(nodes)

    def upstream_filter(graph: BELGraph, u: BaseEntity, v: BaseEntity, k: str) -> bool:
        """Pass for relations for which one of the given nodes is the object."""
        return v in nodes and graph[u][v][k][RELATION] in CAUSAL_RELATIONS

    return upstream_filter
888475
function apply (data, predicates) {
    assert.array(data);

    if (isFunction(predicates)) {
      return data.map(function (value) {
        return predicates(value);
      });
    }

    assert.array(predicates);
    assert.hasLength(data, predicates.length);

    return data.map(function (value, index) {
      return predicates[index](value);
    });
  }
1276946
def key_exists(self, namespace, key):
        

        return namespace in self.__data and key in self.__data[namespace]
968416
def build_downstream_edge_predicate(nodes: Iterable[BaseEntity]) -> EdgePredicate:
    """"""
    nodes = set(nodes)

    def downstream_filter(graph: BELGraph, u: BaseEntity, v: BaseEntity, k: str) -> bool:
        """Pass for relations for which one of the given nodes is the subject."""
        return u in nodes and graph[u][v][k][RELATION] in CAUSAL_RELATIONS

    return downstream_filter
189567
function hasKey(key) {
    return data.meta[key] !== undefined
      && (self.lookup[key] === null ||
      self.lookup[key] === data.meta[key]);
  }
970653
def matches_key_in_query(self, key, query_key, query):
        
        dumped = query.dump()
        dumped['className'] = query._query_class._class_name
        self._add_condition(key, '$select', {'key': query_key, 'query': dumped})
        return self
1369843
def get(self, key: Any, default: Any=None) -> Any:
        ''''''

        return self.data.get(key, default)
381953
def _filter_subgraph(self, subgraph, predicate):
        
        to_return = []

        for unique_id, item in subgraph.items():
            if predicate(item):
                to_return.append(item)

        return to_return
1341663
private GraphCentricQueryBuilder has(String key, TitanPredicate predicate, Object condition) {
        Preconditions.checkNotNull(key);
        Preconditions.checkNotNull(predicate);
        Preconditions.checkArgument(predicate.isValidCondition(condition), "Invalid condition: %s", condition);
        constraints.add(new PredicateCondition<>(key, predicate, condition));
        return this;
    }
1147126
def filter_keys(self, **kwargs):
        ""
        self._used_index = False
        keys = set(self.data.keys())
        for key_filter, v_filter in kwargs.items():
            if key_filter in self.indexes:
                self._used_index = True
                if v_filter not in self.indexes[key_filter]:
                    keys = set([])
                else:
                    keys = keys.intersection(
                        self.indexes[key_filter][v_filter])
            else:
                keys = keys.intersection(
                    self.simple_filter(key_filter, v_filter))
        return keys
362435
def setFilterData(self, key, value):
        
        self._filterData[nativestring(key)] = nativestring(value)