Skip to content

Commit

Permalink
Merge: Tools use model index
Browse files Browse the repository at this point in the history
Add `model_index` inside `model_view` so importing `model_index` automatically provide an index within the view. Also migrate documentation tools to model index.

### nitx

Model index is used to search mentities in commands (like `Array`, or `doc: Array`)
Improvement: nitx can no suggest entities if nothing was found.

### nitdoc

Model index is used to render doc commands in README files (like `[[list: Array]]`, or `[[graph: Array]]`)

Improvements:
* user can use `name` or `full_name` to locate entities
* nitdoc check and suggest errors
* nitdoc check and display short name conflicts

### nitweb

Model index is used to render doc down inputs and benefits now from the same improvements than nitdoc (but with a different implementation).

Futur PR will migrate the quick search engine.

Pull-Request: #2290
Reviewed-by: Jean Privat <[email protected]>
  • Loading branch information
privat committed Aug 26, 2016
2 parents ea2fafc + 75928aa commit 3718cfe
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 169 deletions.
32 changes: 16 additions & 16 deletions lib/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@ Core classes and methods used by default by Nit programs and libraries.

## Core Basic Types and Operations

[[doc:kernel]]
[[doc: kernel]]

### Object

[[doc:Object]]
[[doc: Object]]

#### Equality

[[doc:Object::==]]
[[doc:Object::!=]]
[[doc:Object::hash]]
[[doc:Object::is_same_instance]]
[[doc:Object::object_id]]
[[doc: core::Object::==]]
[[doc: core::Object::!=]]
[[doc: core::Object::hash]]
[[doc: core::Object::is_same_instance]]
[[doc: core::Object::object_id]]

#### Debuging

[[doc:Object::output]]
[[doc:Object::output_class_name]]
[[doc:Object::is_same_type]]
[[doc: core::Object::output]]
[[doc: core::Object::output_class_name]]
[[doc: core::Object::is_same_type]]

### Sys

[[doc:Sys]]
[[doc: Sys]]

#### Program Execution

[[doc:Sys::main]]
[[doc:Sys::run]]
[[doc: core::Sys::main]]
[[doc: core::Sys::run]]

### Other

[[list:kernel]]
[[list: kernel]]

## Core Collections

[[doc:collection]]
[[doc: collection]]

## String and Text manipulation

[[doc:text]]
[[doc: text]]
8 changes: 4 additions & 4 deletions lib/github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This module provides a Nit object oriented interface to access the Github api.

### Authentification

[[doc: GithubAPI::auth]]
[[doc: auth]]

Token can also be recovered from user config with `get_github_oauth`.

Expand All @@ -28,7 +28,7 @@ Token can also be recovered from user config with `get_github_oauth`.

### Other data

[[list: api]]
[[list: github::api]]

### Advanced uses

Expand All @@ -38,11 +38,11 @@ Token can also be recovered from user config with `get_github_oauth`.

#### Custom requests

[[doc: GithubAPI::get]]
[[doc: github::GithubAPI::get]]

#### Change the user agent

[[doc: GithubAPI::user_agent]]
[[doc: github::GithubAPI::user_agent]]

#### Debugging

Expand Down
26 changes: 13 additions & 13 deletions lib/nlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,41 @@ For ease of use, this wrapper introduce a Nit model to handle CoreNLP XML result

[[doc: NLPDocument]]

[[doc: NLPDocument::from_xml]]
[[doc: NLPDocument::from_xml_file]]
[[doc: NLPDocument::sentences]]
[[doc: nlp::NLPDocument::from_xml]]
[[doc: nlp::NLPDocument::from_xml_file]]
[[doc: nlp::NLPDocument::sentences]]

### NLPSentence

[[doc: NLPSentence]]

[[doc: NLPSentence::tokens]]
[[doc: nlp::NLPSentence::tokens]]

### NLPToken

[[doc: NLPToken]]

[[doc: NLPToken::word]]
[[doc: NLPToken::lemma]]
[[doc: NLPToken::pos]]
[[doc: nlp::NLPToken::word]]
[[doc: nlp::NLPToken::lemma]]
[[doc: nlp::NLPToken::pos]]

### NLP Processor

[[doc: NLPProcessor]]

[[doc: NLPProcessor::java_cp]]
[[doc: nlp::NLPProcessor::java_cp]]

[[doc: NLPProcessor::process]]
[[doc: NLPProcessor::process_file]]
[[doc: NLPProcessor::process_files]]
[[doc: nlp::NLPProcessor::process]]
[[doc: nlp::NLPProcessor::process_file]]
[[doc: nlp::NLPProcessor::process_files]]

## Vector Space Model

[[doc: NLPVector]]

[[doc: NLPDocument::vector]]
[[doc: vector]]

[[doc: NLPVector::cosine_similarity]]
[[doc: nlp::NLPVector::cosine_similarity]]

## NitNLP binary

Expand Down
85 changes: 65 additions & 20 deletions src/doc/doc_phases/doc_console.nit
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import semantize
import doc_commands
import doc_poset
import doc::console_templates
import model::model_index

# Nitx handles console I/O.
#
Expand Down Expand Up @@ -95,7 +96,11 @@ class Nitx
return
end
var res = query.perform(self, doc)
var page = query.make_results(self, res)
var suggest = null
if res.is_empty then
suggest = query.suggest(self, doc)
end
var page = query.make_results(self, res, suggest)
print page.write_to_string
end
end
Expand All @@ -118,12 +123,44 @@ redef interface DocCommand
# Looks up the `doc` model and returns possible matches.
fun perform(nitx: Nitx, doc: DocModel): Array[NitxMatch] is abstract

# Looks up the `doc` model and returns possible suggestions.
fun suggest(nitx: Nitx, doc: DocModel): nullable Array[MEntity] do
return find_suggestions(doc, args.first)
end

# Pretty prints the results for the console.
fun make_results(nitx: Nitx, results: Array[NitxMatch]): DocPage do
fun make_results(nitx: Nitx, results: Array[NitxMatch], suggest: nullable Array[MEntity]): DocPage do
var page = new DocPage("results", "Results")
page.root.add_child(new QueryResultArticle("results", "Results", self, results))
page.root.add_child(new QueryResultArticle("results", "Results", self, results, suggest))
return page
end

# Lookup mentities based on a `query` string.
#
# 1- lookup by first name (returns always one value)
# 2- lookup by name (can return conflicts)
fun find_mentities(doc: DocModel, query: String): Array[MEntityMatch] do
var res = new Array[MEntityMatch]

# First lookup by full_name
var mentity = doc.mentity_by_full_name(query)
if mentity != null then
res.add new MEntityMatch(self, mentity)
return res
end

# If no results, lookup by name
for m in doc.mentities_by_name(query) do
res.add new MEntityMatch(self, m)
end

return res
end

# Suggest some mentities based on a `query` string.
fun find_suggestions(doc: DocModel, query: String): Array[MEntity] do
return doc.find(query, 3)
end
end

# Something that matches a `DocCommand`.
Expand All @@ -147,16 +184,9 @@ class MEntityMatch
end

redef class CommentCommand
redef fun perform(nitx, doc) do
var name = args.first
var res = new Array[NitxMatch]
for mentity in doc.mentities_by_name(name) do
res.add new MEntityMatch(self, mentity)
end
return res
end
redef fun perform(nitx, doc) do return find_mentities(doc, args.first)

redef fun make_results(nitx, results) do
redef fun make_results(nitx, results, suggest) do
var len = results.length
if len == 1 then
var res = results.first.as(MEntityMatch)
Expand Down Expand Up @@ -266,7 +296,7 @@ redef class ArticleCommand
return res
end

redef fun make_results(nitx, results) do
redef fun make_results(nitx, results, suggest) do
var len = results.length
# FIXME how to render the pager for one worded namespaces like "core"?
if len == 1 then
Expand Down Expand Up @@ -304,7 +334,7 @@ end
abstract class HierarchiesQuery
super DocCommand

redef fun make_results(nitx, results) do
redef fun make_results(nitx, results, suggest) do
var page = new DocPage("hierarchy", "Hierarchy")
for result in results do
if not result isa PageMatch then continue
Expand Down Expand Up @@ -382,15 +412,15 @@ redef class CodeCommand
return res
end
# else, lookup the model by name
for mentity in doc.mentities_by_name(name) do
if mentity isa MClass then continue
if mentity isa MProperty then continue
res.add new CodeMatch(self, mentity.cs_location, mentity.cs_source_code)
for match in find_mentities(doc, name) do
if match.mentity isa MClass then continue
if match.mentity isa MProperty then continue
res.add new CodeMatch(self, match.mentity.cs_location, match.mentity.cs_source_code)
end
return res
end

redef fun make_results(nitx, results) do
redef fun make_results(nitx, results, suggest) do
var page = new DocPage("results", "Code Results")
for res in results do
page.add new CodeQueryArticle("results", "Results", self, res.as(CodeMatch))
Expand Down Expand Up @@ -487,10 +517,25 @@ private class QueryResultArticle
# Results to display.
var results: Array[NitxMatch]

# Optional suggestion when no matches where found
var suggest: nullable Array[MEntity] = null is optional

redef fun render_title do
var len = results.length
if len == 0 then
add "No result found for '{query.string}'..."
addn "No result found for '{query.string}'..."
var suggest = self.suggest
if suggest != null and suggest.not_empty then
add "\nDid you mean "
var i = 0
for s in suggest do
add "`{s.full_name}`"
if i == suggest.length - 2 then add ", "
if i == suggest.length - 1 then add " or "
i += 1
end
add "?"
end
else
add "# {len} result(s) for '{query.string}'".green.bold
end
Expand Down
Loading

0 comments on commit 3718cfe

Please sign in to comment.