CoolFace
Apppublic

Danielchris145/TruthCheck-AI

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
claim_extractor.py35 linesDownload Raw Back to models
1# models/claim_extractor.py2import re3import spacy4 5class ClaimExtractor:6    def __init__(self): # Corrected __init__7        try:8            self.nlp = spacy.load("en_core_web_sm")9        except OSError:10            print("Please install spaCy English model: python -m spacy download en_core_web_sm")11            raise12    13    def extract_claims(self, text):14        """Extract factual claims from text"""15        if not text or len(text.strip()) < 10:16            return []17        18        # Use spaCy for sentence segmentation19        doc = self.nlp(text)20        claims = []21        22        for sent in doc.sents:23            sentence = sent.text.strip()24            25            # Filter out questions, commands, and short sentences26            if (len(sentence.split()) > 5 and 27                not sentence.endswith('?') and 28                not sentence.startswith(('How', 'What', 'When', 'Where', 'Why', 'Who')) and29                not re.match(r'^(Please|Let|Can you)', sentence, re.IGNORECASE)):30                31                claims.append(sentence)32        33        return claims if claims else [text.strip()]34 35