Esempio n. 1
0
def find_duplicate_links(a, decided_atoms):
    """Find the duplicated, non-duplicated links from decided atoms list.

    Args:
        a: An instance of AtomSpace.
        decided_atoms: The source atoms to make new atom.
        :param a: opencog.atomspace.AtomSpace
        :param decided_atoms: list[Atom]
    Returns:
        duplicate_links: Duplicated link tuples list.
        non_duplicate_links: Non-duplicated links list.
        :rtype : (list[list[EqualLinkKey]], list[EqualLinkKey])
    """
    # ex) atom_link_pairs =
    # {
    #   <a1>: [<l1, type=a>, <l2, type=b>, <l3, type=c>]
    #   <a2>: [<l4, type=a>, <l5, type=x>, <l6, type=y>]
    # }
    atom_link_pairs = {}

    for atom in decided_atoms:
        original_links = atom.incoming_by_type(types.Link)
        equal_links = link_to_keys(a, original_links, atom)
        atom_link_pairs[atom.handle_uuid()] = equal_links

    # ex) inverted_links_index =
    # {
    #   <type=a>: [<l1, type=a>, <l4, type=a>]
    #   <type=b>: [<l2, type=b>]
    #   <type=c>: [<l3, type=c>]
    #   <type=x>: [<l5, type=x>]
    #   <type=y>: [<l6, type=y>]
    # }
    inverted_links_index = get_inverted_index_value(atom_link_pairs)

    # ex) duplicate_links =
    # [
    #   [<l1, type=a>, <l4, type=a>]
    # ]

    # ex) non_duplicate_links =
    # {
    #   [<l2, type=b>]
    #   [<l3, type=c>]
    #   [<l5, type=x>]
    #   [<l6, type=y>]
    # }
    duplicate_links = []
    non_duplicate_links = []

    for item in inverted_links_index.itervalues():
        duplicate_links.append(item) if len(item) > 1 \
            else non_duplicate_links.extend(item)

    return duplicate_links, non_duplicate_links
Esempio n. 2
0
def find_duplicate_links(a, decided_atoms):
    """Find the duplicated, non-duplicated links from decided atoms list.

    Args:
        a: An instance of AtomSpace.
        decided_atoms: The source atoms to make new atom.
        :param a: opencog.atomspace.AtomSpace
        :param decided_atoms: list[Atom]
    Returns:
        duplicate_links: Duplicated link tuples list.
        non_duplicate_links: Non-duplicated links list.
        :rtype : (list[list[EqualLinkKey]], list[EqualLinkKey])
    """
    # ex) atom_link_pairs =
    # {
    #   <a1>: [<l1, type=a>, <l2, type=b>, <l3, type=c>]
    #   <a2>: [<l4, type=a>, <l5, type=x>, <l6, type=y>]
    # }
    atom_link_pairs = {}

    for atom in decided_atoms:
        original_links = a.get_atoms_by_target_atom(types.Link, atom)
        equal_links = link_to_keys(a, original_links, atom)
        atom_link_pairs[atom.handle_uuid()] = equal_links

    # ex) inverted_links_index =
    # {
    #   <type=a>: [<l1, type=a>, <l4, type=a>]
    #   <type=b>: [<l2, type=b>]
    #   <type=c>: [<l3, type=c>]
    #   <type=x>: [<l5, type=x>]
    #   <type=y>: [<l6, type=y>]
    # }
    inverted_links_index = get_inverted_index_value(atom_link_pairs)

    # ex) duplicate_links =
    # [
    #   [<l1, type=a>, <l4, type=a>]
    # ]

    # ex) non_duplicate_links =
    # {
    #   [<l2, type=b>]
    #   [<l3, type=c>]
    #   [<l5, type=x>]
    #   [<l6, type=y>]
    # }
    duplicate_links = []
    non_duplicate_links = []

    for item in inverted_links_index.itervalues():
        duplicate_links.append(item) if len(item) > 1 \
            else non_duplicate_links.extend(item)

    return duplicate_links, non_duplicate_links
Esempio n. 3
0
def find_duplicate_links(a, decided_atoms):
    # ex) atom_link_pairs =
    # {
    #   <a1>: [<l1, type=a>, <l2, type=b>, <l3, type=c>]
    #   <a2>: [<l4, type=a>, <l5, type=x>, <l6, type=y>]
    # }
    atom_link_pairs = {}

    for atom in decided_atoms:
        original_links = a.get_atoms_by_target_atom(types.Link, atom)
        equal_links = link_to_keys(a, original_links, atom)
        atom_link_pairs[atom.handle_uuid()] = equal_links

    # ex) inverted_links_index =
    # {
    #   <type=a>: [<l1, type=a>, <l4, type=a>]
    #   <type=b>: [<l2, type=b>]
    #   <type=c>: [<l3, type=c>]
    #   <type=x>: [<l5, type=x>]
    #   <type=y>: [<l6, type=y>]
    # }
    inverted_links_index = get_inverted_index_value(atom_link_pairs)

    # ex) duplicate_links =
    # [
    #   [<l1, type=a>, <l4, type=a>]
    # ]

    # ex) non_duplicate_links =
    # {
    #   [<l2, type=b>]
    #   [<l3, type=c>]
    #   [<l5, type=x>]
    #   [<l6, type=y>]
    # }
    duplicate_links = []
    non_duplicate_links = []

    for item in inverted_links_index.itervalues():
        duplicate_links.append(item) if len(item) > 1 \
            else non_duplicate_links.append(item)

    return duplicate_links, non_duplicate_links
Esempio n. 4
0
def find_related_links(
        a,
        decided_atoms,
        inter_info_strength_above_limit
):
    """Find the all related links from decided atoms list.

    It estimates that related links are all of links in inherited nodes.

    Args:
        a: An instance of AtomSpace.
        decided_atoms: The source atoms to make new atom.
        inter_info_strength_above_limit: A max value of strength in TruthValue
        during interaction information generation.
        :param a: opencog.atomspace.AtomSpace
        :param decided_atoms: list[Atom]
        :param inter_info_strength_above_limit: float
    Returns:
        related_node_target_links: Target link tuples in related node list.
        :rtype : list[list[EqualLinkKey]]
    """
    # Evaluate inheritance relation,
    # and copy all link in each inheritance node.
    related_node_target_links = list()

    for decided_atom in decided_atoms:
        inheritance_node_set = find_inheritance_nodes(a, decided_atom)
        for related_node in inheritance_node_set:
            # Manually throw away the links have low strength.
            target_links = filter(
                lambda link:
                    (link.tv.mean > inter_info_strength_above_limit),
                a.get_atoms_by_target_atom(types.Link, related_node)
            )
            related_node_target_links.append(
                link_to_keys(a, target_links, related_node)
            )

    return related_node_target_links