File size: 1,617 Bytes
e5ab379
6dad1de
 
e5ab379
 
6dad1de
 
 
 
 
 
e5ab379
6dad1de
 
e5ab379
 
 
6dad1de
 
 
 
 
 
 
e5ab379
 
 
 
6dad1de
 
 
 
 
 
 
e5ab379
6dad1de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from typing import Dict, Any, List
import numpy as np
from datetime import datetime
from tinytroupe.agent import TinyPerson
from tinytroupe.agent.social_types import Content
from tinytroupe.social_network import NetworkTopology

class ContentFeatureExtractor:
    def extract(self, content: Content) -> Dict[str, float]:
        """Extract all content features"""
        return {
            "word_count": float(len(content.text.split())),
            "has_image": 1.0 if content.images else 0.0,
            "has_video": 1.0 if content.video_url else 0.0,
            "has_link": 1.0 if content.external_links else 0.0,
            "sentiment_score": content.sentiment,
            "num_hashtags": float(len(content.hashtags)),
            "is_weekend": 1.0 if content.timestamp.weekday() >= 5 else 0.0,
        }

class PersonaFeatureExtractor:
    def extract(self, persona: TinyPerson) -> Dict[str, float]:
        """Extract persona features"""
        return {
            "age": float(persona._persona.get("age") or 30),
            "num_connections": float(len(persona.social_connections)),
            "influence_score": persona.influence_metrics.authority,
            "engagement_rate": persona.engagement_patterns.get("overall_rate", 0.0),
        }

class InteractionFeatureExtractor:
    def extract(self, persona: TinyPerson, content: Content, network: NetworkTopology) -> Dict[str, float]:
        """Extract features from persona-content interaction context"""
        return {
            "topic_alignment": persona.get_content_affinity(content),
            # "num_friends_engaged": ...
        }