mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-07 21:54:54 +03:00
WIP COMMENT OUT BROKEN CODE
This commit is contained in:
parent
2cbee66953
commit
7294c42b27
|
@ -1,9 +1,9 @@
|
||||||
import React, { Fragment } from 'react'
|
import React, { Fragment } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
|
// import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
|
||||||
import 'prismjs-bibtex'
|
// import 'prismjs-bibtex'
|
||||||
import rangeParser from 'parse-numeric-range'
|
// import rangeParser from 'parse-numeric-range'
|
||||||
import { window } from 'browser-monads'
|
import { window } from 'browser-monads'
|
||||||
|
|
||||||
import CUSTOM_TYPES from '../../meta/type-annotations.json'
|
import CUSTOM_TYPES from '../../meta/type-annotations.json'
|
||||||
|
@ -69,7 +69,11 @@ export const TypeAnnotation = ({ lang = 'python', link = true, children }) => {
|
||||||
const code = Array.isArray(children) ? children.join('') : children || ''
|
const code = Array.isArray(children) ? children.join('') : children || ''
|
||||||
const [rawText, meta] = code.split(/(?= \(.+\)$)/)
|
const [rawText, meta] = code.split(/(?= \(.+\)$)/)
|
||||||
const rawStr = rawText.replace(/\./g, TMP_DOT)
|
const rawStr = rawText.replace(/\./g, TMP_DOT)
|
||||||
const rawHtml = lang === 'none' || !code ? code : highlightCode(lang, rawStr)
|
const rawHtml =
|
||||||
|
lang === 'none' || !code
|
||||||
|
? code
|
||||||
|
: // highlightCode(lang, rawStr)
|
||||||
|
''
|
||||||
const html = rawHtml.replace(new RegExp(TMP_DOT, 'g'), '.').replace(/\n/g, ' ')
|
const html = rawHtml.replace(new RegExp(TMP_DOT, 'g'), '.').replace(/\n/g, ' ')
|
||||||
const result = htmlToReact(html)
|
const result = htmlToReact(html)
|
||||||
const elements = Array.isArray(result) ? result : [result]
|
const elements = Array.isArray(result) ? result : [result]
|
||||||
|
@ -159,7 +163,8 @@ function convertLine(line, i) {
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const htmlLine = replacePrompt(highlightCode('bash', line), '$')
|
const htmlLine = line
|
||||||
|
// replacePrompt(highlightCode('bash', line), '$')
|
||||||
return htmlToReact(htmlLine)
|
return htmlToReact(htmlLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,9 +195,9 @@ function formatCode(html, lang, prompt) {
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.map((line, i) => {
|
.map((line, i) => {
|
||||||
let newLine = prompt ? replacePrompt(line, prompt, i === 0) : line
|
let newLine = prompt ? replacePrompt(line, prompt, i === 0) : line
|
||||||
if (lang === 'diff' && !line.startsWith('<')) {
|
// if (lang === 'diff' && !line.startsWith('<')) {
|
||||||
newLine = highlightCode('python', line)
|
// newLine = highlightCode('python', line)
|
||||||
}
|
// }
|
||||||
return newLine
|
return newLine
|
||||||
})
|
})
|
||||||
.join('\n')
|
.join('\n')
|
||||||
|
@ -219,26 +224,26 @@ export class Code extends React.Component {
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
}
|
}
|
||||||
|
|
||||||
updateJuniper() {
|
// updateJuniper() {
|
||||||
if (this.state.Juniper == null && window.Juniper !== null) {
|
// if (this.state.Juniper == null && window.Juniper !== null) {
|
||||||
this.setState({ Juniper: window.Juniper })
|
// this.setState({ Juniper: window.Juniper })
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
componentDidMount() {
|
// componentDidMount() {
|
||||||
this.updateJuniper()
|
// this.updateJuniper()
|
||||||
}
|
// }
|
||||||
|
|
||||||
componentDidUpdate() {
|
// componentDidUpdate() {
|
||||||
this.updateJuniper()
|
// this.updateJuniper()
|
||||||
}
|
// }
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { lang, title, executable, github, prompt, wrap, highlight, className, children } =
|
const { lang, title, executable, github, prompt, wrap, highlight, className, children } =
|
||||||
this.props
|
this.props
|
||||||
const codeClassNames = classNames(classes['code'], className, `language-${lang}`, {
|
const codeClassNames = classNames(classes.code, className, `language-${lang}`, {
|
||||||
[classes['wrap']]: !!highlight || !!wrap || lang === 'cli',
|
[classes.wrap]: !!highlight || !!wrap || lang === 'cli',
|
||||||
[classes['cli']]: lang === 'cli',
|
[classes.cli]: lang === 'cli',
|
||||||
})
|
})
|
||||||
const ghClassNames = classNames(codeClassNames, classes['max-height'])
|
const ghClassNames = classNames(codeClassNames, classes['max-height'])
|
||||||
const { Juniper } = this.state
|
const { Juniper } = this.state
|
||||||
|
@ -255,10 +260,11 @@ export class Code extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
const codeText = Array.isArray(children) ? children.join('') : children || ''
|
const codeText = Array.isArray(children) ? children.join('') : children || ''
|
||||||
const highlightRange = highlight ? rangeParser.parse(highlight).filter((n) => n > 0) : []
|
// const highlightRange = highlight ? rangeParser.parse(highlight).filter((n) => n > 0) : []
|
||||||
const rawHtml = ['none', 'cli'].includes(lang)
|
const rawHtml = ['none', 'cli'].includes(lang)
|
||||||
? codeText
|
? codeText
|
||||||
: highlightCode(lang, codeText, highlightRange)
|
: // highlightCode(lang, codeText, highlightRange)
|
||||||
|
codeText
|
||||||
const html = formatCode(rawHtml, lang, prompt)
|
const html = formatCode(rawHtml, lang, prompt)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import { navigate } from 'gatsby'
|
// import { navigate } from 'gatsby'
|
||||||
|
|
||||||
import * as classes from '../styles/dropdown.module.sass'
|
import * as classes from '../styles/dropdown.module.sass'
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ export default function Dropdown({ defaultValue, className, onChange, children }
|
||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
window.location.href = target.value
|
window.location.href = target.value
|
||||||
} else {
|
} else {
|
||||||
navigate(target.value)
|
// navigate(target.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
|
// import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
|
||||||
|
|
||||||
import Icon from './icon'
|
import Icon from './icon'
|
||||||
import Link from './link'
|
import Link from './link'
|
||||||
|
@ -39,7 +39,11 @@ const GitHubCode = ({ url, lang, errorMsg = defaultErrorMsg, className }) => {
|
||||||
}
|
}
|
||||||
}, [initialized, rawUrl, errorMsg])
|
}, [initialized, rawUrl, errorMsg])
|
||||||
|
|
||||||
const highlighted = lang === 'none' || !code ? code : highlightCode(lang, code)
|
const highlighted =
|
||||||
|
lang === 'none' || !code
|
||||||
|
? code
|
||||||
|
: // highlightCode(lang, code)
|
||||||
|
null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
|
// import { graphql } from 'gatsby'
|
||||||
import useOnlineStatus from '@rehooks/online-status'
|
import useOnlineStatus from '@rehooks/online-status'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
|
|
||||||
|
|
|
@ -318,7 +318,7 @@ const Model = ({
|
||||||
</tbody>
|
</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
{meta.notes & <MarkdownToReact markdown={meta.notes} />}
|
{meta.notes & <MarkdownToReact markdown={meta.notes} />}
|
||||||
{hasInteractiveCode && (
|
{/* {hasInteractiveCode && (
|
||||||
<CodeBlock title="Try out the model" lang="python" executable={true}>
|
<CodeBlock title="Try out the model" lang="python" executable={true}>
|
||||||
{[
|
{[
|
||||||
`import spacy`,
|
`import spacy`,
|
||||||
|
@ -331,7 +331,7 @@ const Model = ({
|
||||||
` print(token.text, token.pos_, token.dep_)`,
|
` print(token.text, token.pos_, token.dep_)`,
|
||||||
].join('\n')}
|
].join('\n')}
|
||||||
</CodeBlock>
|
</CodeBlock>
|
||||||
)}
|
)} */}
|
||||||
{meta.accuracy && (
|
{meta.accuracy && (
|
||||||
<Accordion id={`${name}-accuracy`} title="Accuracy Evaluation">
|
<Accordion id={`${name}-accuracy`} title="Accuracy Evaluation">
|
||||||
<Table>
|
<Table>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { Fragment } from 'react'
|
import React, { Fragment } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Link as GatsbyLink } from 'gatsby'
|
// import { Link as GatsbyLink } from 'gatsby'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
|
|
||||||
import Icon from './icon'
|
import Icon from './icon'
|
||||||
|
|
|
@ -117,10 +117,10 @@ const Quickstart = ({
|
||||||
const dropdownGetter = showDropdown[id] || (() => true)
|
const dropdownGetter = showDropdown[id] || (() => true)
|
||||||
return hidden ? null : (
|
return hidden ? null : (
|
||||||
<div key={id} data-quickstart-group={id} className={classes['group']}>
|
<div key={id} data-quickstart-group={id} className={classes['group']}>
|
||||||
<style data-quickstart-style={id} scoped>
|
{/* <style data-quickstart-style={id} scoped>
|
||||||
{styles[id] ||
|
{styles[id] ||
|
||||||
`[data-quickstart-results]>[data-quickstart-${id}] { display: none }`}
|
`[data-quickstart-results]>[data-quickstart-${id}] { display: none }`}
|
||||||
</style>
|
</style> */}
|
||||||
<div className={classes['legend']}>
|
<div className={classes['legend']}>
|
||||||
{title}
|
{title}
|
||||||
{help && (
|
{help && (
|
||||||
|
|
|
@ -7,23 +7,23 @@ import * as classes from '../styles/search.module.sass'
|
||||||
|
|
||||||
export default function Search({ id = 'docsearch', placeholder = 'Search docs', settings = {} }) {
|
export default function Search({ id = 'docsearch', placeholder = 'Search docs', settings = {} }) {
|
||||||
const { apiKey, indexName, appId } = settings
|
const { apiKey, indexName, appId } = settings
|
||||||
if (!apiKey && !indexName) return null
|
|
||||||
const [initialized, setInitialized] = useState(false)
|
const [initialized, setInitialized] = useState(false)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
setInitialized(true)
|
setInitialized(true)
|
||||||
window.docsearch({
|
// window.docsearch({
|
||||||
appId,
|
// appId,
|
||||||
apiKey,
|
// apiKey,
|
||||||
indexName,
|
// indexName,
|
||||||
inputSelector: `#${id}`,
|
// inputSelector: `#${id}`,
|
||||||
debug: false,
|
// debug: false,
|
||||||
})
|
// })
|
||||||
}
|
}
|
||||||
}, [initialized, apiKey, indexName, id])
|
}, [initialized, apiKey, indexName, id])
|
||||||
|
if (!apiKey && !indexName) return null
|
||||||
return (
|
return (
|
||||||
<form className={classes.root}>
|
<form className={classes.root}>
|
||||||
<label htmlFor={id} className={classes.icon}>
|
{/* <label htmlFor={id} className={classes.icon}>
|
||||||
<Icon name="search" width={20} />
|
<Icon name="search" width={20} />
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
|
@ -32,7 +32,7 @@ export default function Search({ id = 'docsearch', placeholder = 'Search docs',
|
||||||
type="search"
|
type="search"
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
aria-label={placeholder}
|
aria-label={placeholder}
|
||||||
/>
|
/> */}
|
||||||
</form>
|
</form>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,6 +216,9 @@ const QuickstartInstall = ({ id, title }) => {
|
||||||
</QS>
|
</QS>
|
||||||
|
|
||||||
{languages.map(({ code, models: modelOptions }) => {
|
{languages.map(({ code, models: modelOptions }) => {
|
||||||
|
if (!modelOptions) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const pkg = modelOptions[efficiency ? 0 : modelOptions.length - 1]
|
const pkg = modelOptions[efficiency ? 0 : modelOptions.length - 1]
|
||||||
return (
|
return (
|
||||||
<QS models={code} key={code}>
|
<QS models={code} key={code}>
|
||||||
|
|
|
@ -81,6 +81,9 @@ const QuickstartInstall = ({ id, title, description, children }) => {
|
||||||
copy={false}
|
copy={false}
|
||||||
>
|
>
|
||||||
{languages.map(({ code, models, example }) => {
|
{languages.map(({ code, models, example }) => {
|
||||||
|
if (!models) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const pkg = efficiency ? models[0] : models[models.length - 1]
|
const pkg = efficiency ? models[0] : models[models.length - 1]
|
||||||
const exampleText = example || 'No text available yet'
|
const exampleText = example || 'No text available yet'
|
||||||
return lang !== code ? null : (
|
return lang !== code ? null : (
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
|
// import highlightCode from 'gatsby-remark-prismjs/highlight-code.js'
|
||||||
|
|
||||||
import { Quickstart } from '../components/quickstart'
|
import { Quickstart } from '../components/quickstart'
|
||||||
import generator, { DATA as GENERATOR_DATA } from './quickstart-training-generator'
|
// import generator, { DATA as GENERATOR_DATA } from './quickstart-training-generator'
|
||||||
import { htmlToReact } from '../components/util'
|
import { htmlToReact } from '../components/util'
|
||||||
|
|
||||||
const DEFAULT_LANG = 'en'
|
const DEFAULT_LANG = 'en'
|
||||||
|
@ -70,75 +70,73 @@ const DATA = [
|
||||||
]
|
]
|
||||||
|
|
||||||
export default function QuickstartTraining({ id, title, download = 'base_config.cfg' }) {
|
export default function QuickstartTraining({ id, title, download = 'base_config.cfg' }) {
|
||||||
const [lang, setLang] = useState(DEFAULT_LANG)
|
// const [lang, setLang] = useState(DEFAULT_LANG)
|
||||||
const [_components, _setComponents] = useState([])
|
// const [_components, _setComponents] = useState([])
|
||||||
const [components, setComponents] = useState([])
|
// const [components, setComponents] = useState([])
|
||||||
const [[hardware], setHardware] = useState([DEFAULT_HARDWARE])
|
// const [[hardware], setHardware] = useState([DEFAULT_HARDWARE])
|
||||||
const [[optimize], setOptimize] = useState([DEFAULT_OPT])
|
// const [[optimize], setOptimize] = useState([DEFAULT_OPT])
|
||||||
const [textcatExclusive, setTextcatExclusive] = useState(DEFAULT_TEXTCAT_EXCLUSIVE)
|
// const [textcatExclusive, setTextcatExclusive] = useState(DEFAULT_TEXTCAT_EXCLUSIVE)
|
||||||
|
// function updateComponents(value, isExclusive) {
|
||||||
|
// _setComponents(value)
|
||||||
|
// const updated = value.map(c => (c === 'textcat' && !isExclusive ? 'textcat_multilabel' : c))
|
||||||
|
// setComponents(updated)
|
||||||
|
// }
|
||||||
|
// const setters = {
|
||||||
|
// lang: setLang,
|
||||||
|
// components: v => updateComponents(v, textcatExclusive),
|
||||||
|
// hardware: setHardware,
|
||||||
|
// optimize: setOptimize,
|
||||||
|
// textcat: v => {
|
||||||
|
// const isExclusive = v.includes('exclusive')
|
||||||
|
// setTextcatExclusive(isExclusive)
|
||||||
|
// updateComponents(_components, isExclusive)
|
||||||
|
// },
|
||||||
|
// }
|
||||||
|
// const defaultData = GENERATOR_DATA.__default__
|
||||||
|
// const reco = GENERATOR_DATA[lang] || defaultData
|
||||||
|
// const content = generator({
|
||||||
|
// lang,
|
||||||
|
// components,
|
||||||
|
// optimize,
|
||||||
|
// hardware,
|
||||||
|
// transformer_data: reco.transformer || defaultData.transformer,
|
||||||
|
// word_vectors: reco.word_vectors,
|
||||||
|
// has_letters: reco.has_letters,
|
||||||
|
// })
|
||||||
|
// const rawStr = content.trim().replace(/\n\n\n+/g, '\n\n')
|
||||||
|
// const rawContent = `${COMMENT}\n${rawStr}`
|
||||||
|
// const displayContent = ''
|
||||||
|
// // highlightCode('ini', rawContent)
|
||||||
|
// // .split('\n')
|
||||||
|
// // .map(line => (line.startsWith('#') ? `<span class="token comment">${line}</span>` : line))
|
||||||
|
// // .join('\n')
|
||||||
|
// let data = DATA
|
||||||
|
// data[0].dropdown = models.languages
|
||||||
|
// .map(({ name, code }) => ({
|
||||||
|
// id: code,
|
||||||
|
// title: name,
|
||||||
|
// }))
|
||||||
|
// .sort((a, b) => a.title.localeCompare(b.title))
|
||||||
|
// if (!_components.includes('textcat')) {
|
||||||
|
// data = data.map(field => (field.id === 'textcat' ? { ...field, hidden: true } : field))
|
||||||
|
// }
|
||||||
|
// return (
|
||||||
|
// <Quickstart
|
||||||
|
// id="quickstart-widget"
|
||||||
|
// Container="div"
|
||||||
|
// download={download}
|
||||||
|
// rawContent={rawContent}
|
||||||
|
// data={data}
|
||||||
|
// title={title}
|
||||||
|
// id={id}
|
||||||
|
// setters={setters}
|
||||||
|
// hidePrompts
|
||||||
|
// small
|
||||||
|
// codeLang="ini"
|
||||||
|
// >
|
||||||
|
// {htmlToReact(displayContent)}
|
||||||
|
// </Quickstart>
|
||||||
|
// )
|
||||||
|
|
||||||
function updateComponents(value, isExclusive) {
|
return <></>
|
||||||
_setComponents(value)
|
|
||||||
const updated = value.map((c) =>
|
|
||||||
c === 'textcat' && !isExclusive ? 'textcat_multilabel' : c
|
|
||||||
)
|
|
||||||
setComponents(updated)
|
|
||||||
}
|
|
||||||
|
|
||||||
const setters = {
|
|
||||||
lang: setLang,
|
|
||||||
components: (v) => updateComponents(v, textcatExclusive),
|
|
||||||
hardware: setHardware,
|
|
||||||
optimize: setOptimize,
|
|
||||||
textcat: (v) => {
|
|
||||||
const isExclusive = v.includes('exclusive')
|
|
||||||
setTextcatExclusive(isExclusive)
|
|
||||||
updateComponents(_components, isExclusive)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const defaultData = GENERATOR_DATA.__default__
|
|
||||||
const reco = GENERATOR_DATA[lang] || defaultData
|
|
||||||
const content = generator({
|
|
||||||
lang,
|
|
||||||
components,
|
|
||||||
optimize,
|
|
||||||
hardware,
|
|
||||||
transformer_data: reco.transformer || defaultData.transformer,
|
|
||||||
word_vectors: reco.word_vectors,
|
|
||||||
has_letters: reco.has_letters,
|
|
||||||
})
|
|
||||||
const rawStr = content.trim().replace(/\n\n\n+/g, '\n\n')
|
|
||||||
const rawContent = `${COMMENT}\n${rawStr}`
|
|
||||||
const displayContent = highlightCode('ini', rawContent)
|
|
||||||
.split('\n')
|
|
||||||
.map((line) => (line.startsWith('#') ? `<span class="token comment">${line}</span>` : line))
|
|
||||||
.join('\n')
|
|
||||||
|
|
||||||
let data = DATA
|
|
||||||
data[0].dropdown = models.languages
|
|
||||||
.map(({ name, code }) => ({
|
|
||||||
id: code,
|
|
||||||
title: name,
|
|
||||||
}))
|
|
||||||
.sort((a, b) => a.title.localeCompare(b.title))
|
|
||||||
if (!_components.includes('textcat')) {
|
|
||||||
data = data.map((field) => (field.id === 'textcat' ? { ...field, hidden: true } : field))
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<Quickstart
|
|
||||||
id="quickstart-widget"
|
|
||||||
Container="div"
|
|
||||||
download={download}
|
|
||||||
rawContent={rawContent}
|
|
||||||
data={data}
|
|
||||||
title={title}
|
|
||||||
id={id}
|
|
||||||
setters={setters}
|
|
||||||
hidePrompts
|
|
||||||
small
|
|
||||||
codeLang="ini"
|
|
||||||
>
|
|
||||||
{htmlToReact(displayContent)}
|
|
||||||
</Quickstart>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user