monkslc / hyperpolyglot

A fast programming language detector
Apache License 2.0
56 stars 13 forks source link

How to do heuristics only based on text not extension? #10

Open pvonmoradi opened 2 years ago

pvonmoradi commented 2 years ago

For example grab a C file, change its extension to .go. All github-linguist, enry and hyperpolyglot detect it as a Go source. If I remove the extension, hyperpolyglot returns empty.

StringKe commented 7 months ago
[dependencies]
hyperpolyglot = { git = "https://github.com/StringKe/hyperpolyglot.git", branch = "master" }
fn main() {
    let content = r#"
   use clipboard_rs::{ClipboardContext, ClipboardHandler};

pub struct ClipboardManager {
    ctx: ClipboardContext,
}

impl ClipboardManager {
    pub fn new() -> Self {
        Self {
            ctx: ClipboardContext::new().unwrap(),
        }
    }
}

impl ClipboardHandler for ClipboardManager {
    fn on_clipboard_change(&mut self) {
        println!("Clipboard changed");
    }
}
    "#;
    let result = hyperpolyglot::detectors::classify(content, &*vec![]);
    println!("{}", result.to_string());
}