gomoss

package module
v0.0.0-...-8cd4736 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2018 License: BSD-3-Clause Imports: 15 Imported by: 0

README

Gomoss

Go client for Moss plagiarism software detector.

Introduction

This is Go interface for Moss client. It is written for omegaUp project

Installation

go get -u github.com/SpaceWhite/gomoss

Usage

See the docs here

License

This project is licensed under BSD-3-Clause

Documentation

Overview

Gomoss is Go interface for Moss client http://theory.stanford.edu/~aiken/moss/

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRegion = errors.New("Invalid region")
)
View Source
var (
	ErrLanguageNotSupported = errors.New("Language is not supported")
)

Functions

func Download

func Download(ctx context.Context, ref *url.URL, dirName string) error

Download downloads all HTML files from given URL recursively

Example
urlStruct, err := url.Parse("http://moss.stanford.edu/results/NUMBER")
if err != nil {
	panic(err)
}

// Context is used to terminate Download process
ctx := context.Background()
dir := "moss.education.com"
err = os.Mkdir(dir, 644)
if err != nil {
	panic(err)
}
defer os.RemoveAll(dir)

err = Download(ctx, urlStruct, dir)
if err != nil {
	panic(err)
}

func DownloadURL

func DownloadURL(ref *url.URL, filename string) error

DownloadURL downloads HTML to file from given URL

Types

type Address

type Address struct {
	Host string
	Port string
}

Address is end point of Moss plagiarism detector

type Match

type Match struct {
	Left, Right Source
}

Match compares two source codes potential plagiarism results

type MossRequest

type MossRequest struct {
	// ID is the Moss server user ID
	ID uint32
	// Language is programing language type
	Language string
	// Ignore limit
	IgnoreLimit uint16
	// Comment is comment that will appear on result
	Comment string
	// EndPoint is Moss plagiarism detector endpoint
	EndPoint *Address
	// ExperimentalServer is flag utilize experimental server
	ExperimentalServer uint8
	// MatchingNumber is number of matching files to show in the result
	MatchingNumber uint16
	// DirectoryMode is a mode to add files with directory
	DirectoryMode uint8
	// Code is source codes that will be sent to Moss server
	Code codeList
	// BaseCode is base codes that will be sent to Moss server
	BaseCode codeList
}

MossRequest contains Moss client ID and configuration parameter

func NewRequest

func NewRequest(userID uint32) *MossRequest

NewRequest creates a new instance of MossRequest

Example
// Get this ID from https://theory.stanford.edu/~aiken/moss/
// ID must be uint32
mossID := uint32(12345678)

// Create new request from Moss ID
request := NewRequest(mossID)

// Change the default parameters
// For more information about parameters see http://moss.stanford.edu/general/scripts/mossnet
request.IgnoreLimit = 30
request.MatchingNumber = 100
request.Language = "cc"

func (*MossRequest) Submit

func (request *MossRequest) Submit(ctx context.Context) (*url.URL, error)

Submit function sends codes and base codes with its configuration to Moss server

Example
mossID := uint32(12345678)
request := NewRequest(mossID)

sampleFile, err := os.Open("testdata/helloworld.c")
if err != nil {
	panic(err)
}
request.Code.Add(sampleFile, "helloworld.c")

// or load files with for iteration
for _, filename := range []string{"a.c", "b.c"} {
	f, err := os.Open(path.Join("testdata", filename))
	if err != nil {
		panic(err)
	}
	defer f.Close()
	request.Code.Add(f, filename)
}

// Add BaseCode
// If BaseCode is supplied program code that appears in the BaseCode is not counted in matches
baseFile, _ := os.Open("testdata/base.c")
request.BaseCode.Add(baseFile, "base.c")
defer sampleFile.Close()

ctx := context.Background()
url, err := request.Submit(ctx)
if err != nil {
	panic(err)
}
fmt.Println(url)

type Region

type Region struct {
	From int64
	To   int64
}

Region specifies similarity from line a to line b

type Report

type Report struct {
	Matches []Match
}

Report is data extracted data from Moss URL

func Extract

func Extract(ctx context.Context, ref *url.URL) (*Report, error)

Extract extracts data from given Moss URL into Report struct

Example
// Context is used to terminate Extract process
urlStruct, err := url.Parse("http://moss.stanford.edu/results/NUMBER")
if err != nil {
	panic(err)
}

// Context is used to terminate Download process
ctx := context.Background()
results, err := Extract(ctx, urlStruct)
if err != nil {
	panic(err)
}

// View results in json
for _, match := range results.Matches {
	js, _ := json.Marshal(match)
	fmt.Println(string(js))
}

type Source

type Source struct {
	Filename   string
	Similarity float64
	Regions    []Region
}

Source is structure that contains plagiarism result of a source code

Jump to

Keyboard shortcuts

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