示例#1
0
 def test_apply_with_no_language_returns_default(self):
     request = AnalyzeRequest()
     request.analyzeTemplate.language = ''
     request.analyzeTemplate.resultsScoreThreshold = 0
     new_field = request.analyzeTemplate.fields.add()
     new_field.name = 'CREDIT_CARD'
     new_field.minScore = '0.5'
     request.text = "My credit card number is 4916994465041084"
     response = self.loaded_analyzer_engine.Apply(request, None)
     assert response.analyzeResults is not None
def test_when_allFields_is_true_and_entities_not_empty_exception():
    analyze_engine = AnalyzerEngine(registry=RecognizerRegistry(),
                                    nlp_engine=NlpEngineMock())
    request = AnalyzeRequest()
    request.text = "My name is David and I live in Seattle." "Domain: microsoft.com "
    request.analyzeTemplate.allFields = True
    new_field = request.analyzeTemplate.fields.add()
    new_field.name = "CREDIT_CARD"
    new_field.minScore = "0.5"
    with pytest.raises(ValueError):
        analyze_engine.Apply(request, None)
def test_apply_with_language_returns_correct_response(loaded_analyzer_engine):
    request = AnalyzeRequest()
    request.analyzeTemplate.language = "en"
    request.analyzeTemplate.resultsScoreThreshold = 0
    new_field = request.analyzeTemplate.fields.add()
    new_field.name = "CREDIT_CARD"
    new_field.minScore = "0.5"
    request.text = "My credit card number is 4916994465041084"
    response = loaded_analyzer_engine.Apply(request, None)

    assert response.analyzeResults is not None
def test_when_allFields_is_true_full_recognizers_list_return_all_fields(
        nlp_engine):
    analyze_engine = AnalyzerEngine(registry=RecognizerRegistry(),
                                    nlp_engine=nlp_engine)
    request = AnalyzeRequest()
    request.analyzeTemplate.allFields = True
    request.text = "My name is David and I live in Seattle." "Domain: microsoft.com "
    response = analyze_engine.Apply(request, None)
    returned_entities = [field.field.name for field in response.analyzeResults]
    assert response.analyzeResults is not None
    assert "DOMAIN_NAME" in returned_entities
def test_when_allFields_is_true_return_all_fields():
    analyze_engine = AnalyzerEngine(registry=MockRecognizerRegistry(),
                                    nlp_engine=NlpEngineMock())
    request = AnalyzeRequest()
    request.analyzeTemplate.allFields = True
    request.analyzeTemplate.resultsScoreThreshold = 0
    request.text = (
        " Credit card: 4095-2609-9393-4932,  my phone is 425 8829090 "
        "Domain: microsoft.com")
    response = analyze_engine.Apply(request, None)
    returned_entities = [field.field.name for field in response.analyzeResults]

    assert response.analyzeResults is not None
    assert "CREDIT_CARD" in returned_entities
    assert "PHONE_NUMBER" in returned_entities
    assert "DOMAIN_NAME" in returned_entities