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 ¶
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)
}
Types ¶
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 ¶
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 Report ¶
type Report struct {
Matches []Match
}
Report is data extracted data from Moss URL
func Extract ¶
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))
}
Click to show internal directories.
Click to hide internal directories.