<commit_before>package main

import (
	"fmt"
	"os"
	"path"
	"path/filepath"
)

type Path struct {
	Name  string
	Count int
}

func NewPath(name string) *Path {
	return &Path{name, 1}
}

type Shortcut struct {
	Path *Path
	// TODO: manage several paths
	// paths []*Path
}

func NewShortcut(path string) *Shortcut {
	return &Shortcut{NewPath(path)}
}

type Shortcuts map[string]*Shortcut

func NewShortcuts() Shortcuts {
	return make(map[string]*Shortcut)
}

func (s Shortcuts) Get(req string) string {
	if shortcut, ok := s[req]; ok {
		fmt.Println("Shortcut found:", shortcut)
		return shortcut.Path.Name
	}

	return ""
}

func (s Shortcuts) Add(req string) (string, error) {
	// Check path
	info, err := os.Stat(req)
	if err != nil {
		return "", err
	}

	// Path must be valid dir
	if !info.IsDir() {
		return "", os.ErrNotExist
	}

	// Add to paths map
	resp, err := filepath.Abs(req)
	if err != nil {
		return "", err

	}

	// Add shortcut for each subfile
	for resp != "/" {
		d, b := path.Dir(resp), path.Base(resp)
		if _, ok := s[b]; !ok {
			s[b] = NewShortcut(resp)
			fmt.Println("New shortcut created:", b, "->", resp)
		} else {
			fmt.Println("Shortcut updated:", b, "->", resp)
		}
		resp = d
	}

	s[filepath.Base(req)] = NewShortcut(resp)
	fmt.Println("Paths:", s)
	fmt.Println("Response:", resp)

	return resp, nil

}<commit_msg>Manage several values by shortcuts<commit_after>package main

import (
	"fmt"
	"os"
	"path"
	"path/filepath"
)

type Shortcut struct {
	Main  string         // Main path
	Paths map[string]int // All paths managed by shortcut
}

func NewShortcut(path string) *Shortcut {
	return &Shortcut{path, map[string]int{path: 1}}
}

func (s *Shortcut) Update(path string) {
	if _, ok := s.Paths[path]; ok {
		s.Paths[path]++
		if s.Paths[path] > s.Paths[s.Main] {
			s.Main = path
		}
	} else {
		s.Paths[path] = 1
	}
}

type Shortcuts map[string]*Shortcut

func NewShortcuts() Shortcuts {
	return make(map[string]*Shortcut)
}

func (s Shortcuts) Get(req string) string {
	if shortcut, ok := s[req]; ok {
		fmt.Println("Shortcut found:", shortcut)
		return shortcut.Main
	}

	return ""
}

func (s Shortcuts) Add(req string) (string, error) {
	// Check path
	info, err := os.Stat(req)
	if err != nil {
		return "", err
	}

	// Path must be valid dir
	if !info.IsDir() {
		return "", os.ErrNotExist
	}

	// Add to paths map
	resp, err := filepath.Abs(req)
	if err != nil {
		return "", err

	}

	// Add shortcut for each subfile
	for resp != "/" {
		d, b := path.Dir(resp), path.Base(resp)
		if _, ok := s[b]; !ok {
			s[b] = NewShortcut(resp)
			fmt.Println("New shortcut created:", b, "->", s[b])
		} else {
			s[b].Update(resp)
			fmt.Println("Shortcut updated:", b, "->", s[b])
		}
		resp = d
	}

	return resp, nil
}
{'fraction_non_alphanumeric': 0.1644880174291939, 'fraction_numerical': 0.0010893246187363835, 'mean_word_length': 3.291277258566978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3159650', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1050, 'n_words': 286}