**Input:** , the DAG of the KBN; |

* *: the evidence nodes in (the new ad’s keywords); |

* ** *: the non-evidence nodes in (all keywords except for the new ad’s keywords); |

* *: the set of values of the evidence (set 1 as the value); |

* *: the query variable (the keyword will be inferred); |

* *: the total times of sampling. |

**Output:** The estimates of |

**Variables:** |

* *: the set of the values of the non-evidence; |

* *; |

* *: the current state of the KBN; |

* *: the number of the samples when the value of is 1 |

**Steps:** |

(1) Initialization: |

* * values of in *Z * |

* * |

* * |

(2) For to Do |

* * (i) Compute the probabilities of the selected variables based on the state , |

* * Randomly select one non-evidence variable from : |

* * * * , where is the set of the values in the |

* * Markov chain of in the current state |

* *(ii) Generate a random number and we determine the value of : |

* * (5) |

* * |

* *(iii) Count |

* * If Then |

* *End For |

(3) Estimate |

* * |