How to correct my rule to prevent duplicate taxonomy terms to be created? This is a followup of my question at How to create a rule to combine the terms of 2 fields to create a new term and store it in a 3rd field?.

How can I prevent that each time a node is viewed, it creates duplicate taxonomy terms, as shown in this example:



Any suggestions?
I think the Rules condition, URL Alias Exists is perfect for this scenario if put into two rules, one for yes and one for no. Taxonomy terms will have an alias once created so it's easy to check if /taxonomy_vocabulary/[A][B] exists before doing anything with C.

When the node is created or updated, the rules check for A and B added together to see if that AB taxonomy term already exists since every taxonomy term has an alias. If it already exists (yes), the rule fetches it and uses it and if not (no), it creates it.

For example, the first time a node is created or updated with A: New and B: York, "/cities/newyork" wouldn't exist so we create it. The next time we use A: New and B: York, the rule finds the existing term and fetches it.

The below assumes a single-language taxonomy vocabulary. The nodes can be multi-lingual.

PSUEDO-RULES

Rule 1 - Taxonomy C exists
Events: Node is saved / Node is updated
Condition: URL Alias Exists &gt; Use replacement patterns to join A and B in Value field
              eg. taxonomy/[a][b]
Action: Create variable &gt; [a][b] 
Action: Fetch Entity by Property &gt; Taxonomy Term &gt; Name &gt; Created Variable
Action: Set Data Value &gt; C: Fetched Entity:0

Rule 2 - Taxonomy C doesn't exist yet
Events: Node is saved / Node is updated
Condition: NOT URL Alias Exists &gt; Use replacement patterns to join A and B in Value field
Action: Create entity &gt; Taxonomy Term &gt; "AB" using replacement patterns 
              (not the drop-down list!) 
Action: Set Data Value &gt; C: Created Entity


Rules exports
To test these rules, you'll need a Drupal install with Articles, Tags and no Pathauto messing with the urls.
Add three term reference fields to Article for the Tags Vocabulary.  

Machine Names
field_tax_tags_a 
field_tax_tags_b 
field_tax_tags_c


Rule 1 - AB Term exists so fetch it

{ "rules_exists" : {
    "LABEL" : "Exists",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "path" ],
    "ON" : {
      "node_insert--article" : { "bundle" : "article" },
      "node_update--article" : { "bundle" : "article" }
    },
    "IF" : [
      { "path_alias_exists" : { "alias" : "tags\/[node:field-tax-tags-a][node:field-tax-tags-b]" } }
    ],
    "DO" : [
      { "variable_add" : {
          "USING" : {
            "type" : "text",
            "value" : "[node:field-tax-tags-a][node:field-tax-tags-b]"
          },
          "PROVIDE" : { "variable_added" : { "variable_added" : "Added variable" } }
        }
      },
      { "entity_query" : {
          "USING" : {
            "type" : "taxonomy_term",
            "property" : "name",
            "value" : [ "variable-added" ],
            "limit" : "1"
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "data_set" : { "data" : [ "node:field-tax-tags-c" ], "value" : [ "entity-fetched:0" ] } }
    ]
  }
}


Rule 2 - AB Term doesn't exist so create it

{ "rules_doesn_t_exist" : {
    "LABEL" : "Doesn\u0027t exist",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "path" ],
    "ON" : {
      "node_insert--article" : { "bundle" : "article" },
      "node_update--article" : { "bundle" : "article" }
    },
    "IF" : [
      { "NOT path_alias_exists" : { "alias" : "tags\/[node:field-tax-tags-a][node:field-tax-tags-b]" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "taxonomy_term",
            "param_name" : "[node:field-tax-tags-a][node:field-tax-tags-b]",
            "param_vocabulary" : "tags"
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : { "data" : [ "node:field-tax-tags-c" ], "value" : [ "entity-created" ] } }
    ]
  }
}


After that, create and edit some articles only using A and B. C matches and instead of duplicating, will fetch the existing term.