1

Ich verwende Watson Personality Insights, um Ergebnisse aus einem Textkörper zu erhalten. Die Ergebnisse, die ich aus der Demo Node.js Personality Insights erhalte, unterscheiden sich von den Ergebnissen, die ich bei der Verwendung des Python SDK erhalte.Verschiedene WPI v3-Ergebnisse von Python und Node.js

Python Script:

with open('input_file.txt', encoding='utf-8') as input_file: 
    profile = personality_insights.profile(
     input_file.read(), content_type='text/plain;charset=utf-8', 
     raw_scores=True, consumption_preferences=True) 

    print(profile) 

Python Ausgabe: (nur agreeableness Noten unter Zugabe Zeichengrenze bleiben)

{ 
     "trait_id": "big5_agreeableness", 
     "name": "Agreeableness", 
     "category": "personality", 
     "percentile": 0.2641097108346445, 
     "raw_score": 0.717124182764663, 
     "children": [{ 
       "trait_id": "facet_altruism", 
       "name": "Altruism", 
       "category": "personality", 
       "percentile": 0.5930367181429955, 
       "raw_score": 0.7133462509414262 
      }, 
      { 
       "trait_id": "facet_cooperation", 
       "name": "Cooperation", 
       "category": "personality", 
       "percentile": 0.49207238025136585, 
       "raw_score": 0.5781918028043768 
      }, 
      { 
       "trait_id": "facet_modesty", 
       "name": "Modesty", 
       "category": "personality", 
       "percentile": 0.7504251965616365, 
       "raw_score": 0.4840369062774408 
      }, 
      { 
       "trait_id": "facet_morality", 
       "name": "Uncompromising", 
       "category": "personality", 
       "percentile": 0.4144135962141314, 
       "raw_score": 0.6156094284542545 
      }, 
      { 
       "trait_id": "facet_sympathy", 
       "name": "Sympathy", 
       "category": "personality", 
       "percentile": 0.8204286367393345, 
       "raw_score": 0.6984933017082747 
      }, 
      { 
       "trait_id": "facet_trust", 
       "name": "Trust", 
       "category": "personality", 
       "percentile": 0.5357101531393991, 
       "raw_score": 0.5894943830064112 
      } 
     ] 
    } 

Node.js Script:

fs.readFile('input_file.txt', 'utf-8', function (err,data) { 
    var params={}; 
    params.text=data; 
    params.content_type='text/plain; charset=utf-8'; 
    params.raw_scores=true; 
    params.consumption_preferences=true; 

    personality_insights.profile(params, function(error, response) { 
    console.log(JSON.stringify(response)); 
    }); 
}); 

Node.js Ausgabe:

{ 
       "id": "Agreeableness", 
       "name": "Agreeableness", 
       "category": "personality", 
       "percentage": 0.2798027409516949, 
       "sampling_error": 0.101059064, 
       "children": [{ 
        "id": "Altruism", 
        "name": "Altruism", 
        "category": "personality", 
        "percentage": 0.597937110939136, 
        "sampling_error": 0.07455418080000001 
       }, { 
        "id": "Cooperation", 
        "name": "Cooperation", 
        "category": "personality", 
        "percentage": 0.46813215597029234, 
        "sampling_error": 0.0832951302 
       }, { 
        "id": "Modesty", 
        "name": "Modesty", 
        "category": "personality", 
        "percentage": 0.7661123497302398, 
        "sampling_error": 0.0594182198 
       }, { 
        "id": "Morality", 
        "name": "Uncompromising", 
        "category": "personality", 
        "percentage": 0.42178661415240626, 
        "sampling_error": 0.0662383546 
       }, { 
        "id": "Sympathy", 
        "name": "Sympathy", 
        "category": "personality", 
        "percentage": 0.8252000440378008, 
        "sampling_error": 0.1022423736 
       }, { 
        "id": "Trust", 
        "name": "Trust", 
        "category": "personality", 
        "percentage": 0.5190032062613837, 
        "sampling_error": 0.0600995984 
       }] 
      } 

Die Eingabedatei für beide ist das gleiche:

Operations at ports in the U.S. Southeast are shut as the region copes with the changing path of one hurricane even as another is churning toward the region. Hurricane Irma was downgraded to a Category 1 storm as it pushed up through western and central Florida, the WSJ’s Arian Campo-Flores and Joseph De Avila report. That put the Port Tampa Bay in its path but left major trade gateways on the Atlantic coast, including Jacksonville, Georgia’s Port of Savannah and South Carolina Port of Charleston largely outside the storm’s strongest force. The second Category 4 storm to reach the U.S. this season lashed the Miami area with powerful winds and sheets of rain, and both Florida coasts were preparing for severe storm surges and flooding as it headed north and likely toward Georgia. With the storm following so soon after Hurricane Harvey hit the Gulf Coast and a third storm, Jose, heading north, the U.S. issued a rare waiver of the Jones Act, the federal law that prohibits foreign ships from operating in domestic sea routes, the WSJ’s Costas Paris reports. The action will allow foreign tankers to distribute fuel to hurricane-stricken areas. 

Es gibt eine Diskrepanz in den von den beiden Ansätzen empfangenen Werte. Die Werte sind für beide Skripts gleich, wenn content_type=text/plain das Hinzufügen des Attributs charset=utf-8 scheint nicht einen Unterschied in den Ergebnissen über den Python-Code erhalten.

+0

Können Sie bitte die Rückgabe für jedes Codebeispiel hinzufügen? –

Antwort

0

Wie Sie sehen können, wenn die params für text/plain, Watson gesetzt API schlagen die param zu verwenden: Accept: application/json weil der gewünschte Inhaltstyp der response, Sie CSV oder JSON Format wählen können.

Zum Beispiel:

profile(text, content_type='text/plain', content_language=None, 
    accept='application/json', accept_language=None, raw_scores=False, 
    consumption_preferences=False, csv_headers=False) 

Wichtig: In Ihrem Beispiel mit Python, setzen Sie nur print die profile, und verwenden Sie nicht die indent für das Grund ziemlich Druckergebnis wie der Knoten dafür zu bekommen . Ich denke, vielleicht ist es dein Problem mit der Rückkehr.

So versuchen print(json.dumps(profile, indent=2)) zu verwenden, anstatt print(profile)

ich das Beispiel von der API-Referenz habe mit Python und Node, und ich erhalte das gleiche Ergebnis.

Python Beispiel für die Verwendung von Personality Insight:

personality_insights = PersonalityInsightsV3(
    version='2016-10-20', 
    username='{username}', 
    password='{password}') 

with open(join(dirname(__file__), './profile.json')) as profile_json: 
    profile = personality_insights.profile(
    profile_json.read(), content_type='application/json', 
    raw_scores=True, consumption_preferences=True) 

print(json.dumps(profile, indent=2)) 

Knoten Beispiel für die Verwendung von Personality Insight:

var PersonalityInsightsV3 = require('watson-developer-cloud/personality-insights/v3'); 
var personality_insights = new PersonalityInsightsV3({ 
    username: '{username}', 
    password: '{password}', 
    version_date: '2016-10-20' 
}); 

var params = { 
    // Get the content items from the JSON file. 
    content_items: require('./profile.json').contentItems, 
    consumption_preferences: true, 
    raw_scores: true, 
    headers: { 
    'accept-language': 'en', 
    'accept': 'application/json' 
    } 
}; 

personality_insights.profile(params, function(error, response) { 
    if (error) 
    console.log('Error:', error); 
    else 
    console.log(JSON.stringify(response, null, 2)); 
    } 
); 
+0

Danke für die Antwort. Ich habe die Ausgabe für beide hinzugefügt. Das Problem scheint beim Lesen der Eingabedatei zu liegen, da die Anzahl der an WPI gesendeten Wörter unterschiedlich ist, auch wenn die gleiche Datei gelesen wird. –

+0

Versuchen Sie, meine WICHTIG markierten fett gedruckt –

Verwandte Themen