def filter_classes(classes, included_namespaces=(), included_ontologies=()):
    """Filter out classes whos namespace is not in `included_namespaces`
    or whos ontology name is not in one of the ontologies in
    `included_ontologies`.

    `classes` should be a sequence of classes.
    """
    filtered = set(classes)
    if included_namespaces:
        filtered = set(c for c in filtered
                       if c.namespace.name in included_namespaces)
    if included_ontologies:
        filtered = set(c for c in filtered
                       if c.namespace.ontology.name in included_ontologies)
    return filtered