Skip to main content

Streamlined Custom Norming

This guide provides a streamlined approach designed for users who want effective results without diving deep into code. While the Developer Resources offer greater flexibility, this method balances ease of use with reliable outputs, making it an option for those looking to implement custom norming.

Creating a Custom Norm Context

import pandas as pd
import receptiviti
import os
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

# Read credentials from environment
RECEPTIVITI_KEY = os.getenv("RECEPTIVITI_KEY")
RECEPTIVITI_SECRET = os.getenv("RECEPTIVITI_SECRET")
RECEPTIVITI_URL = os.getenv("RECEPTIVITI_URL")

# Confirm that you're authenticated with Receptiviti
receptiviti.status()

# Set verbose logging, version, and other options for the norming function
verbose = True
version = "v2"
options = {
"min_word_count":100,
"max_punctuation": 0.5
}

# Specify the file and column to process
file_path = "input.csv" # Ensure this is set to the actual CSV file
text_column = "Text" # Ensure this matches the column containing language data
norming_name = "my-norming-context" # Set your custom norming context

# Ensure the file exists
if not os.path.isfile(file_path):
raise FileNotFoundError(f"File '{file_path}' not found.")

# Execute the norming function with the provided parameters
results = receptiviti.norming(
key=os.getenv("RECEPTIVITI_KEY"),
secret=os.getenv("RECEPTIVITI_SECRET"),
url=os.getenv("RECEPTIVITI_URL"),
verbose=verbose,
version=version,
options=options,
text=file_path,
text_column=text_column,
name=norming_name
)

# Print results
print("Norming Analysis Results:")
print(results)
info

You can add the line receptiviti.norming() to your script after authenticating to see a list of custom norming contexts that exist in your account.

Norming Your Data to Your Custom Context

import pandas as pd
import receptiviti
import os
from dotenv import load_dotenv

# Load environment variables from .env file

load_dotenv()

# Read credentials from environment

RECEPTIVITI_KEY = os.getenv("RECEPTIVITI_KEY")
RECEPTIVITI_SECRET = os.getenv("RECEPTIVITI_SECRET")
RECEPTIVITI_URL = os.getenv("RECEPTIVITI_URL")

# Ensure credentials are loaded correctly

# Confirm that you're authenticated with Receptiviti
receptiviti.status()

dataset = pd.read_csv("your-dataset.csv")

# Define required variables (ensure these are set correctly)

version = "v2" # Example value; replace with actual version if needed
custom_context = "my-norming-context" # Replace with your custom norming context
verbose = True # Adjust if needed
output_path = "output.csv" # Replace with desired output file path
text_column = "Text" # Adjust to match actual column name
retained_columns = dataset[["Speaker", "Text"]] # Assuming you want to retain all columns from input

# Call Receptiviti API

results = receptiviti.request(
key=os.getenv("RECEPTIVITI_KEY"),
secret=os.getenv("RECEPTIVITI_SECRET"),
url=os.getenv("RECEPTIVITI_URL"),
text="file_name.csv",
version=version,
custom_context=custom_context,
verbose=verbose,
output=output_path,
text_column=text_column
)

# Combine results with retained columns

combined_results = pd.concat([retained_columns.reset_index(drop=True), results.reset_index(drop=True)], axis=1)

# Display and save results

print("Analysis Results:")
print(combined_results)
combined_results.to_csv(output_path, index=False)