1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515
16- # [START language_classify_text_tutorial]
1716"""Using the classify_text method to find content categories of text files,
1817Then use the content category labels to compare text similarity.
1918
@@ -94,7 +93,6 @@ def index(path, index_file):
9493# [END language_classify_text_tutorial_index]
9594
9695
97- # [START language_classify_text_tutorial_split_labels]
9896def split_labels (categories ):
9997 """The category labels are of the form "/a/b/c" up to three levels,
10098 for example "/Computers & Electronics/Software", and these labels
@@ -121,10 +119,8 @@ def split_labels(categories):
121119 _categories [label ] = confidence
122120
123121 return _categories
124- # [END language_classify_text_tutorial_split_labels]
125122
126123
127- # [START language_classify_text_tutorial_similarity]
128124def similarity (categories1 , categories2 ):
129125 """Cosine similarity of the categories treated as sparse vectors."""
130126 categories1 = split_labels (categories1 )
@@ -143,7 +139,6 @@ def similarity(categories1, categories2):
143139 dot += confidence * categories2 .get (label , 0.0 )
144140
145141 return dot / (norm1 * norm2 )
146- # [END language_classify_text_tutorial_similarity]
147142
148143
149144# [START language_classify_text_tutorial_query]
@@ -255,4 +250,3 @@ def query_category(index_file, category_string, n_top=3):
255250 query (args .index_file , args .text )
256251 if args .command == 'query-category' :
257252 query_category (args .index_file , args .category )
258- # [END language_classify_text_tutorial]
0 commit comments