Bourdieu Vectors · Create your Vectors · Search Similar Vectors · Analyse a text · API & Code examples · Evaluations · Datasets · Support

API & Code examples

API

This page shows how to use the BourdieuVectors API with an example POST request for the cultural event "american football" and how to expand all vector fields into separate columns.

Attention: Note that the request limit is 500 vectors / h for unknown vectors or vectors with context. If you need to process a lot of vectors please reach out to me.

How to get a vector

The following POST request returns a vector. It is generated when the input is unknown to the system or returned if already known. When you provide a context the vector is always generated once again.

POST https://api.bourdieuvectors.com/api/v1/vectors Content-Type: application/json{
  "cultural_event": "american football",
  "cultural_event_context": "watching it"
}

Response

{
  "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "cultural_event": "american football",
  "vector": {
    "cultural_capital_cultural_art": 0.1,
    "cultural_capital_education": 0.2,
    ...
  },
  "vector_array": [
    0.1,
    ...
  ],
  "vector_size": 76,
  "model_name": "bourdieuvectors",
  "model_version": "1.0.6"
}

Code

Example R code (POST)

library(httr)
library(jsonlite)
library(dplyr)

data <- data.frame(
  cultural_event = c("american football"),
  stringsAsFactors = FALSE
)

get_vector <- function(event_name) {
  url <- "https://api.bourdieuvectors.com/api/v1/vectors"
  response <- POST(url, body = list(cultural_event = event_name), encode = "json")
  if (status_code(response) == 200) {
    content(response, as = "parsed", type = "application/json")
  } else {
    warning(paste("Failed to fetch for event:", event_name))
    return(NULL)
  }
}

results <- data %>%
  rowwise() %>%
  mutate(api_response = list(get_vector(cultural_event))) %>%
  mutate(across(api_response, ~ if(!is.null(.)) as_tibble(.x$vector) else NULL))

results

Example Python code (POST)

import requests
import pandas as pd

data = pd.DataFrame({
    "cultural_event": ["american football"]
})

def get_vector(event_name: str, event_context: str = ''):
    url = "https://api.bourdieuvectors.com/api/v1/vectors"
    response = requests.post(url, json={"cultural_event": event_name, "cultural_event_context": event_context})
    if response.status_code == 200:
        return response.json()["vector"]
    else:
        print(f"Failed to fetch for event: {event_name}")
        return {}

vector_df = data["cultural_event"].apply(get_vector).apply(pd.Series)
data_expanded = pd.concat([data, vector_df], axis=1)

print(data_expanded)
data_expanded.to_csv("bourdieuvectors_data.csv")