Answers.Body: <p>Maybe this is what you are looking for:
  <a href="https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm</a></p>
  <p>Basically you would</p>
  <ol>
  <li>build and store a finite-state machine that resembles a trie with additional links between the various internal nodes using the given keywords.</li>
  <li>for the candidate document, go through it with the above finite-state machine.</li>
  </ol>
  <p>Then based on the result</p>
  <ol>
  <li>If there is any match, then the document is valid.</li>
  <li>Otherwise it is possible that the document is invalid. However, in terms of the probability, I do not have any good idea yet.</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-07T15:40:22.710Z
Answers.LastActivityDate: 2020-08-07T15:40:22.710Z
Answers.UserDisplayName: Zhengyang SONG
Answers.Body: <p>This is a pretty classic case of document classification via the Naive-Bayes based Bag of Words Algorithm. It'll give you a prior probability based on your keywords. Try <a href="https://www.turing.com/kb/document-classification-using-naive-bayes" rel="nofollow noreferrer">this link</a> for more information. In your specific case, the &quot;Bag&quot; is already pre defined which makes things easier.</p>
  <p>Another related question is <a href="https://datascience.stackexchange.com/questions/102277/binary-document-classification-using-keywords-for-a-very-small-dataset">this</a> which may spawn more ideas for your use case. More generally though, if you format your problem as text classication using a feature vector constructed as some set of counts based on your keyword database then you can use pretty much any ML algorithm which gives you a baysian prior or some output probability.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-23T14:08:50.797Z
Answers.LastActivityDate: 2023-08-23T14:17:34.600Z
Answers.LastEditDate: 2023-08-23T14:17:34.600Z
Answers.UserDisplayName: juicedatom
Body: <p>Let's say that I want to classify whether a document is a legal document or not. I have a list of keywords that will be presented only in legal documents.</p>
  <p>What is the proper way or algorithm to calculate probability based on this list?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-01-04T21:14:24.423Z
Comments.Text: The way this question is posed, it seems trivial: if any/all (depending on interpretation) of the keywords are present in the document, it is a legal document. Else it is undetermined. If this is not what you intended, can you clarify your question?
Comments.UserDisplayName: brazofuerte
Tags: <machine-learning><classification>
Title: How do I classify whether a document is legal or not given a set of keywords that appear only in legal documents?
UserDisplayName: ahmadMarafa
ThreadText: # How do I classify whether a document is legal or not given a set of keywords that appear only in legal documents?
  
  (Asked by: username_0 on 2020-08-05)
  
  Let's say that I want to classify whether a document is a legal document or not. I have a list of keywords that will be presented only in legal documents.
  
  What is the proper way or algorithm to calculate probability based on this list?
  
  **Tags:** machine-learning, classification
  > **Comments:**
  > **username_1**: The way this question is posed, it seems trivial: if any/all (depending on interpretation) of the keywords are present in the document, it is a legal document. Else it is undetermined. If this is not what you intended, can you clarify your question?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-08-07. Score: 0
  
  Maybe this is what you are looking for:
  <https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm>
  
  Basically you would
  
  1. build and store a finite-state machine that resembles a trie with additional links between the various internal nodes using the given keywords.
  2. for the candidate document, go through it with the above finite-state machine.
  
  Then based on the result
  
  1. If there is any match, then the document is valid.
  2. Otherwise it is possible that the document is invalid. However, in terms of the probability, I do not have any good idea yet.
  
  
  ---
  
  ### Answer by username_3 on 2023-08-23. Score: 0
  
  This is a pretty classic case of document classification via the Naive-Bayes based Bag of Words Algorithm. It'll give you a prior probability based on your keywords. Try [this link](https://www.turing.com/kb/document-classification-using-naive-bayes) for more information. In your specific case, the "Bag" is already pre defined which makes things easier.
  
  Another related question is [this](https://datascience.stackexchange.com/questions/102277/binary-document-classification-using-keywords-for-a-very-small-dataset) which may spawn more ideas for your use case. More generally though, if you format your problem as text classication using a feature vector constructed as some set of counts based on your keyword database then you can use pretty much any ML algorithm which gives you a baysian prior or some output probability.
  
  
  ---
  
  