kg

package
v0.0.0-...-a3ff98b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConvertCmd = &cobra.Command{
	Use:   "convert",
	Short: "Convert between knowledge graph formats (e.g., TTL to NQ)",
	RunE: func(cmd *cobra.Command, args []string) error {

		f, err := os.Open(inFile)
		if err != nil {
			return fmt.Errorf("failed to open input file: %w", err)
		}
		defer f.Close()

		format := inFmt
		if format == "" {
			ext := filepath.Ext(inFile)
			switch ext {
			case ".ttl":

				return fmt.Errorf("turtle format (.ttl) is currently not supported")
			case ".nq":
				format = "nquads"
			case ".nt":
				format = "ntriples"
			case ".jsonld":
				format = "jsonld"
			default:
				return fmt.Errorf("unknown input extension %s, please specify --from", ext)
			}
		}

		var r quad.Reader
		switch format {
		case "nquads", "ntriples":

			r = nquads.NewReader(f, false)
		case "jsonld":
			r = jsonld.NewReader(f)
		default:
			return fmt.Errorf("unsupported input format: %s", format)
		}

		outF, err := os.Create(outFile)
		if err != nil {
			return fmt.Errorf("failed to create output file: %w", err)
		}
		defer outF.Close()

		// 4. Encoder
		var w quad.Writer
		switch outFmt {
		case "nquads", "ntriples":

			w = nquads.NewWriter(outF)
		case "jsonld":
			w = jsonld.NewWriter(outF)
		default:
			return fmt.Errorf("unsupported output format: %s", outFmt)
		}

		defer func() {
			if c, ok := w.(io.Closer); ok {
				c.Close()
			}
		}()

		n, err := quad.Copy(w, r)
		if err != nil {
			return fmt.Errorf("conversion failed: %w", err)
		}

		cmd.Printf("Converted %d quads to %s\n", n, outFile)
		return nil
	},
}
View Source
var KgCmd = &cobra.Command{
	Use:   "kg",
	Short: "Knowledge Graph utilities",
	Run: func(cmd *cobra.Command, args []string) {
		cmd.Help()
	},
}

Functions

func AddCommands

func AddCommands(rootCmd *cobra.Command)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL