做一个自动把土味情话转成高级文案的工具,颠覆情话只能囧聊,提高表白成功率。

5 阅读11分钟

土味情话高级转化器 - 让表白更有格调

一、实际应用场景描述

场景背景:

小王是一名数学文化艺术创新创业课程的学生,正在准备向心仪的设计系女生表白。他收集了很多土味情话:

  • "你知道你和星星的区别吗?星星在天上,你在我心里"
  • "你是属什么的?你是属于我的"
  • "我最近买了一块地,什么地?你的死心塌地"

但每次练习说出来,都觉得太尬,怕被当成"普信男"或者"油腻怪"。同时,他也注意到设计系女生平时发朋友圈都是很有文艺范儿的文案,比如"今日份的晚霞是橘子汽水味的"。

痛点分析:

  1. 土味情话太直白:容易让人产生审美疲劳和反感
  2. 缺乏文化深度:只有套路没有内涵,打动不了文艺青年
  3. 场景不匹配:面对高审美人群,低俗梗反而减分
  4. 表达层次单一:无法体现个人的文学素养和数学美感
  5. 心理门槛高:说出口需要很大勇气,因为太"中二"

解决方案:

开发一个基于Python的"土味情话高级转化器",结合数学中的黄金分割美学、斐波那契数列韵律和文学修辞学,将low土味情话转化为具有数学之美和文学之雅的高级表白文案,让表白成功率从"社死边缘"提升到"心动瞬间"。

二、核心逻辑讲解

┌─────────────────────────────────────────────────────────────────────┐ │ 土味情话高级转化器 │ ├─────────────────────────────────────────────────────────────────────┤ │ 输入: 土味情话 (cheesy_text) │ │ ↓ │ │ ┌─────────────────────────────────────────┐ │ │ │ 1. 土味检测器 (Cheesy Detector) │ │ │ │ - 识别套路模板 │ │ │ │ - 分析尬点指数 │ │ │ │ - 提取核心情感 │ │ │ └─────────────────────────────────────────┘ │ │ ↓ │ │ ┌─────────────────────────────────────────┐ │ │ │ 2. 数学美学引擎 (Math Aesthetic Engine) │ │ │ │ - 黄金分割比例应用 │ │ │ │ - 斐波那契韵律生成 │ │ │ │ - 几何意象转换 │ │ │ └─────────────────────────────────────────┘ │ │ ↓ │ │ ┌─────────────────────────────────────────┐ │ │ │ 3. 文学修辞模块 (Literary Rhetoric) │ │ │ │ - 比喻重构 │ │ │ │ - 通感转换 │ │ │ │ - 古典诗词化用 │ │ │ └─────────────────────────────────────────┘ │ │ ↓ │ │ ┌─────────────────────────────────────────┐ │ │ │ 4. 语境适配层 (Context Adapter) │ │ │ │ - 文艺风/数学风/混搭风 │ │ │ │ - 目标人群画像匹配 │ │ │ │ - 场景化润色 │ │ │ └─────────────────────────────────────────┘ │ │ ↓ │ │ 输出: {高级文案, 数学美学指数, 文学格调值, 表白成功概率预测} │ └─────────────────────────────────────────────────────────────────────┘

核心转换公式:

高级文案 = 土味核心情感 × 黄金分割系数 × 文学修辞密度 + 数学美学点缀 表白成功率 = 基础分(30%) + 格调提升(40%) + 创意指数(30%)

三、完整代码实现

项目结构

sweet_converter/ ├── main.py # 主程序入口 ├── cheesy_detector.py # 土味检测器 ├── math_aesthetics.py # 数学美学引擎 ├── literary_rhetoric.py # 文学修辞模块 ├── context_adapter.py # 语境适配层 ├── style_templates.json # 风格模板 ├── golden_ratio_calculator.py # 黄金分割计算器 ├── fibonacci_poet.py # 斐波那契诗人 ├── README.md # 项目说明 └── requirements.txt # 依赖清单

  1. requirements.txt

numpy==1.24.3 jieba==0.42.1 scipy==1.10.1

  1. style_templates.json(风格模板)

{ "math_elegant": { "name": "数学优雅风", "description": "用黄金分割和几何美学包装情话", "prefixes": ["若将我的心看作一个平面", "按黄金分割比例", "在笛卡尔坐标系中"], "connectors": ["则你恰好位于", "与我的距离符合", "构成最美的"], "suffixes": ["的黄金分割点", "斐波那契螺旋的中心", "非欧几何的唯一解"] }, "literary_poetic": { "name": "文学诗意风", "description": "用古典诗词和通感修辞升华情话", "prefixes": ["世间万物皆有裂痕", "你是黄昏时的第一缕光", "若思念有重量"], "connectors": ["那是光照进来的地方", "胜过人间无数星河", "便足以压弯整个春天"], "suffixes": ["而我愿做修补裂痕的匠人", "让我甘愿在暮色中沉沦", "只因你是我唯一的变量"] }, "art_design": { "name": "艺术设计风", "description": "用设计美学和色彩理论诠释情话", "prefixes": ["你的出现", "这世间所有的配色", "如果爱有颜色"], "connectors": ["打破了我原本的极简主义", "都因你而失去意义", "那一定是莫兰迪调的粉"], "suffixes": ["让我开始迷恋复杂的层次", "唯你是不容修改的标准色", "温柔得让时间都慢下来"] }, "philosophical": { "name": "哲学思辨风", "description": "用存在主义和数学哲学包装情话", "prefixes": ["在无限的可能性中", "如果宇宙有中心", "我思故我在的命题里"], "connectors": ["你是我唯一确定的解", "你就是那个奇点", "唯你让存在有了意义"], "suffixes": ["其他都是干扰项", "时间因你而弯曲", "我愿与你共赴无穷远"] } }

  1. golden_ratio_calculator.py(黄金分割计算器)

""" 黄金分割计算器 - 提供数学美学计算功能 作者:AI助手 用途:为情话转换提供黄金分割比例和美学计算 数学文化艺术创新创业课程项目 """

import math from typing import List, Tuple, Dict

class GoldenRatioCalculator: """ 黄金分割计算器

黄金分割 φ = (1 + √5) / 21.618033988749895
在艺术和自然界中广泛存在,被认为是美的标准比例
"""

PHI = (1 + math.sqrt(5)) / 2  # 黄金比例 ≈ 1.618
PHI_INVERSE = 1 / PHI          # 黄金比例的倒数 ≈ 0.618

def __init__(self):
    """初始化计算器"""
    self.fibonacci_cache = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]

def get_golden_ratio(self) -> float:
    """返回黄金分割比例"""
    return self.PHI

def get_inverse_golden_ratio(self) -> float:
    """返回黄金分割的倒数"""
    return self.PHI_INVERSE

def is_golden_rectangle(self, width: float, height: float) -> Dict:
    """
    判断是否为黄金矩形
    
    Args:
        width: 宽度
        height: 高度
        
    Returns:
        dict: 包含比例信息和美学评分
    """
    ratio = max(width, height) / min(width, height)
    difference = abs(ratio - self.PHI)
    
    return {
        "ratio": round(ratio, 4),
        "difference_from_phi": round(difference, 4),
        "is_golden": difference < 0.01,
        "aesthetic_score": max(0, 100 - difference * 50)
    }

def golden_section_text(self, text: str, mode: str = "middle") -> Dict:
    """
    按黄金分割比例分割文本
    
    Args:
        text: 原始文本
        mode: 分割模式 - "middle"(中间), "start"(开头), "end"(结尾)
        
    Returns:
        dict: 分割后的文本片段及其位置
    """
    length = len(text)
    if length < 3:
        return {"segments": [text], "positions": [0]}
    
    # 计算黄金分割点
    golden_point = int(length * self.PHI_INVERSE)
    
    if mode == "middle":
        # 在黄金分割点处分割
        segment1 = text[:golden_point]
        segment2 = text[golden_point:]
        return {
            "segments": [segment1, segment2],
            "positions": [0, golden_point],
            "ratio": round(len(segment1) / len(segment2), 3) if len(segment2) > 0 else 0
        }
    elif mode == "start":
        # 取前黄金比例部分
        return {
            "segments": [text[:golden_point], text[golden_point:]],
            "positions": [0, golden_point],
            "extracted": text[:golden_point]
        }
    else:  # end
        # 取后黄金比例部分
        return {
            "segments": [text[:length-golden_point], text[length-golden_point:]],
            "positions": [0, length-golden_point],
            "extracted": text[length-golden_point:]
        }

def generate_golden_spiral_points(self, n: int = 8) -> List[Tuple[float, float]]:
    """
    生成黄金螺旋的关键点坐标
    
    Args:
        n: 点的数量
        
    Returns:
        list: 坐标点列表
    """
    points = []
    angle = 0
    for i in range(n):
        r = (self.PHI ** (i / 2)) * 0.1
        x = r * math.cos(angle)
        y = r * math.sin(angle)
        points.append((round(x, 4), round(y, 4)))
        angle += math.pi / 2 * self.PHI_INVERSE
    
    return points

def golden_poetry_structure(self, lines: List[str]) -> Dict:
    """
    用黄金分割结构设计诗歌结构
    
    Args:
        lines: 诗句列表
        
    Returns:
        dict: 重新排列的诗结构
    """
    if len(lines) < 3:
        return {"structured": lines, "golden_index": 0}
    
    golden_index = int(len(lines) * self.PHI_INVERSE)
    
    # 黄金分割结构:重要诗句放在黄金分割位置
    structured = lines.copy()
    important_line = structured.pop(golden_index % len(structured))
    structured.insert(golden_index, important_line)
    
    return {
        "structured": structured,
        "golden_index": golden_index,
        "explanation": f"核心诗句置于第{golden_index + 1}行,符合黄金分割美学"
    }

def aesthetic_score(self, elements: Dict) -> float:
    """
    计算美学评分
    
    Args:
        elements: 包含数学美学元素的字典
        
    Returns:
        float: 美学评分 (0-100)
    """
    score = 50  # 基础分
    
    # 黄金比例加分
    if elements.get("has_golden_ratio", False):
        score += 15
    
    # 斐波那契加分
    if elements.get("has_fibonacci", False):
        score += 10
    
    # 对称性加分
    if elements.get("is_symmetric", False):
        score += 10
    
    # 简约性加分
    if elements.get("is_minimalist", False):
        score += 10
    
    # 复杂度惩罚(避免过度装饰)
    complexity = elements.get("complexity", 0)
    score -= complexity * 5
    
    return min(100, max(0, score))

class FibonacciPoet: """ 斐波那契诗人

斐波那契数列:0, 1, 1, 2, 3, 5, 8, 13, 21...
相邻两项的比值趋近于黄金分割比例
在自然和艺术中具有独特的韵律美
"""

def __init__(self):
    """初始化诗人"""
    self.sequence = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]

def get_sequence(self, n: int) -> List[int]:
    """获取前n个斐波那契数"""
    return self.sequence[:n]

def get_rhythm_pattern(self, text: str) -> Dict:
    """
    为文本创建斐波那契节奏模式
    
    Args:
        text: 输入文本
        
    Returns:
        dict: 节奏模式信息
    """
    words = text.split()
    word_count = len(words)
    
    # 找到最接近的斐波那契数
    closest_fib = min(self.sequence, key=lambda x: abs(x - word_count))
    
    # 创建节奏模式
    rhythm = []
    fib_index = 0
    for i, word in enumerate(words):
        if i > 0 and i % self.sequence[fib_index % len(self.sequence)] == 0:
            rhythm.append("|")  # 节奏分隔符
            fib_index += 1
        rhythm.append(word)
    
    return {
        "original_word_count": word_count,
        "closest_fibonacci": closest_fib,
        "rhythm_pattern": " ".join(rhythm),
        "fibonacci_rhythm": self.sequence[:min(fib_index + 1, len(self.sequence))]
    }

def fibonacci_poem(self, theme: str) -> str:
    """
    生成斐波那契结构的短诗
    
    Args:
        theme: 诗歌主题
        
    Returns:
        str: 生成的短诗
    """
    # 斐波那契行长度
    line_lengths = [1, 1, 2, 3, 5, 8, 5, 3, 2, 1, 1]
    
    # 主题相关词汇
    theme_words = {
        "love": ["心", "你", "光", "影", "梦", "念", "暖", "软", "甜", "深"],
        "nature": ["风", "花", "云", "月", "山", "水", "鸟", "叶", "露", "星"],
        "art": ["线", "色", "形", "意", "境", "韵", "美", "真", "善", "创"]
    }
    
    words = theme_words.get(theme, theme_words["love"])
    
    poem_lines = []
    for length in line_lengths:
        if length == 0:
            continue
        line = ""
        for i in range(min(length, len(words))):
            line += words[(len(poem_lines) + i) % len(words)]
        poem_lines.append(line)
    
    return "\n".join(poem_lines)

def generate_fibonacci_phrase(self, base_phrase: str) -> str:
    """
    用斐波那契规律扩写短语
    
    Args:
        base_phrase: 基础短语
        
    Returns:
        str: 扩写后的短语
    """
    words = base_phrase.split()
    if len(words) < 2:
        return base_phrase
    
    result = []
    for i, word in enumerate(words):
        result.append(word)
        # 按斐波那契规律添加修饰
        if i < len(self.sequence) - 1:
            if self.sequence[i + 1] > 2:
                result.append(self._get_modifier(i))
    
    return " ".join(result)

def _get_modifier(self, index: int) -> str:
    """获取修饰词"""
    modifiers = [
        "如黄金般", "似斐波那契般", "带着几何的美", 
        "按着螺旋的轨迹", "在比例中", "于和谐里"
    ]
    return modifiers[index % len(modifiers)]

测试代码

if name == "main": # 测试黄金分割计算器 grc = GoldenRatioCalculator() print(f"黄金比例 φ = {grc.get_golden_ratio():.6f}") print(f"黄金比例倒数 = {grc.get_inverse_golden_ratio():.6f}")

# 测试文本黄金分割
text = "你是我生命中最美的意外遇见你让平凡的日子有了诗意"
result = grc.golden_section_text(text, "middle")
print(f"\n文本黄金分割: {result}")

# 测试斐波那契诗人
fp = FibonacciPoet()
print(f"\n斐波那契数列前10项: {fp.get_sequence(10)}")

rhythm = fp.get_rhythm_pattern("今天的天空是橘色的像你害羞时的脸颊")
print(f"节奏模式: {rhythm}")

poem = fp.fibonacci_poem("love")
print(f"斐波那契情诗:\n{poem}")

4. cheesy_detector.py(土味检测器)

""" 土味检测器 - 识别和分析土味情话的特征 作者:AI助手 用途:识别土味情话的套路模板和尬点 数学文化艺术创新创业课程项目 """

import re from typing import Dict, List, Tuple from collections import Counter

class CheesyDetector: """ 土味情话检测器

通过模式识别和尬点分析,将土味情话解构为核心情感
"""

def __init__(self):
    """初始化检测器"""
    # 土味情话常见套路模板
    self.cheesy_patterns = {
        "comparison": r"你知道你跟(.+?)的区别吗\?(.+?)(我|你)在(.+?),(.+?)(在|是|属于)(.+?)",
        "riddle": r"我最近(.+?),什么(.+?)\?(.+?)(的)?(.+?)(,|\.|!)",
        "confession": r"我(喜|爱|想)你(,|\.)?就像?(.+?)喜欢?(.+?)(,|。|!)",
        "possession": r"你是(属|像)?(.+?)的?\?(.+?)(是|属于|像)我的",
        "pun": r"(.+?)(谐音|同音)于?(.+?),所以?(.+?)(是|属于|像)我的",
        "number": r"我(有|数)过(.+?),一共(.+?)个?,(都|全)是?关于?你的",
        "weather": r"(今天)?(.+?)天气(.+?),我想起(.+?)说过(.+?)",
        "food": r"(吃|喝)(.+?)的时候,(突然)?想起(.+?)说过(.+?)"
    }
    
    # 尬点关键词库
    self.awkward_keywords = [        "美女", "帅哥", "宝贝", "亲爱的", "老婆", "老公",        "我爱你", "我喜欢你", "么么哒", "抱抱", "亲亲",        "你是猪", "脑子进水", "笨蛋", "傻瓜", "蠢货",        "心跳", "扑通扑通", "荷尔蒙", "多巴胺", "肾上腺素",        "宇宙", "银河系", "太阳系", "黑洞", "超新星",        "命中注定", "缘分", "天意", "上帝", "月老"    ]
    
    # 土味程度词汇
    self.cheesy_intensity_words = {
        "mild": ["有点", "稍微", "还行", "一般"],
        "moderate": ["很", "非常", "特别", "相当", "挺"],
        "high": ["超级", "巨", "爆", "炸", "疯狂", "要命", "死"]
    }
    
def detect_pattern(self, text: str) -> Dict:
    """
    检测土味情话的套路模式
    
    Args:
        text: 输入文本
        
    Returns:
        dict: 检测到的模式和匹配信息
    """
    text = text.strip()
    detected_patterns = []
    
    for pattern_name, pattern in self.cheesy_patterns.items():
        match = re.search(pattern, text, re.IGNORECASE)
        if match:
            detected_patterns.append({
                "pattern_type": pattern_name,
                "matched_text": match.group(),
                "groups": match.groups(),
                "confidence": self._calculate_pattern_confidence(pattern_name)
            })
    
    return {
        "has_pattern": len(detected_patterns) > 0,
        "patterns": detected_patterns,
        "pattern_count": len(detected_patterns)
    }

def _calculate_pattern_confidence(self, pattern_type: str) -> float:
    """计算模式检测的置信度"""
    confidence_map = {
        "comparison": 0.85,
        "riddle": 0.90,
        "confession": 0.75,
        "possession": 0.80,
        "pun": 0.88,
        "number": 0.82,
        "weather": 0.70,
        "food": 0.72
    }
    return confidence_map.get(pattern_type, 0.70)

def analyze_awkwardness(self, text: str) -> Dict:
    """
    分析文本的尬点指数
    
    Args:
        text: 输入文本
        
    Returns:
        dict: 尬点分析结果
    """
    words = jieba.lcut(text)
    awkward_matches = []
    
    for keyword in self.awkward_keywords:
        if keyword in text:
            awkward_matches.append(keyword)
    
    # 计算尬点密度
    awkward_density = len(awkward_matches) / len(words) if words else 0
    
    # 检测夸张表达
    exaggeration_score = self._detect_exaggeration(text)
    
    # 检测强行押韵
    rhyme_score = self._detect_forced_rhyme(text)
    
    # 综合尬点指数 (0-100)
    awkward_index = min(100, (
        len(awkward_matches) * 15 +
        awkward_density * 200 +
        exaggeration_score * 25 +
        rhyme_score * 20
    ))
    
    return {
        "awkward_keywords": awkward_matches,
        "awkward_density": round(awkward_density, 4),
        "exaggeration_score": exaggeration_score,
        "rhyme_score": rhyme_score,
        "awkward_index": round(awkward_index, 2),
        "awkward_level": self._get_awkward_level(awkward_index)
    }

def _detect_exaggeration(self, text: str) -> float:
    """检测夸张表达程度"""
    exaggeration_patterns = [
        r"(全世界|全宇宙|全世界)",
        r"(永远|永恒|生生世世|天长地久)",
        r"(唯一|独一无二|绝无仅有)",
        r"(疯狂|要命|死去活来|魂牵梦萦)",
        r"(无数|千万|亿|满天)"
    ]
    
    score = 0
    for pattern in exaggeration_patterns:
        matches = re.findall(pattern, text)
        score += len(matches) * 0.25
    
    return min(1.0, score)

def _detect_forced_rhyme(self, text: str) -> float:
    """检测强行押韵程度"""
    # 简单的韵脚检测
    endings = []
    for char in text:
        if '\u4e00' <= char <= '\u9fff':  # 中文字符
            endings.append(char[-1])
    
    if len(endings) < 4:
        return 0
    
    # 统计韵脚重复
    ending_counts = Counter(endings[-10:])  # 只看最后10个字符
    rhyme_frequency = max(ending_counts.values()) if ending_counts else 0
    
    return min(1.0, rhyme_frequency / 5)

def _get_awkward_level(self, index: float) -> str:
    """获取尬点等级"""
    if index < 20:
        return "😊 清新自然"
    elif index < 40:
        return "🙂 略有套路"
    elif index < 60:
        return "😅 明显土味"
    elif index < 80:
        return "🤣 重度尬撩"
    else:
        return "💀 社死预警"

def extract_core_emotion(self, text: str) -> Dict:
    """
    从土味情话中提取核心情感
    
    Args:
        text: 输入文本
        
    Returns:
        dict: 核心情感信息
    """
    # 情感关键词映射
    emotion_keywords = {
        "admiration": ["美", "漂亮", "好看", "优秀", "棒", "厉害", "完美", "喜欢", "爱"],
        "affection": ["想", "想念", "思念", "牵挂", "惦记", "关心", "在意", "关注"],
        "commitment": ["永远", "一直", "始终", "陪", "守", "等", "属于", "一起"],
        "happiness": ["开心", "快乐", "幸福", "甜蜜", "美好", "暖", "甜", "乐"],
        "longing": ["想见", "盼", "等", "望", "念", "期待", "渴望", "希望"]
    }
    
    # 分析各情感强度
    emotion_scores = {}
    for emotion, keywords in emotion_keywords.items():
        score = sum(1 for keyword in keywords if keyword in text)
        if score > 0:
            emotion_scores[emotion] = score
    
    # 确定主要情感
    if emotion_scores:
        primary_emotion = max(emotion_scores, key=emotion_scores.get)
    else:
        primary_emotion = "affection"  # 默认情感
    
    return {
        "primary_emotion": primary_emotion,
        "emotion_scores": emotion_scores,
        "emotion_description": self._describe_emotion(primary_emotion)
    }

def _describe_emotion(self, emotion: str) -> str:
    """描述情感类型"""
    descriptions = {
        "admiration": "欣赏与赞美",
        "affection": "关怀与喜爱",
        "commitment": "承诺与陪伴",
        "happiness": "快乐

利用AI解决实际问题,如果你觉得这个工具好用,欢迎关注长安牧笛!