小编Jua*_*heh的帖子

nltk正则表达式标记生成器

我尝试在python中使用nltk实现一个正则表达式标记生成器,但结果如下:

>>> import nltk
>>> text = 'That U.S.A. poster-print costs $12.40...'
>>> pattern = r'''(?x)    # set flag to allow verbose regexps
...     ([A-Z]\.)+        # abbreviations, e.g. U.S.A.
...   | \w+(-\w+)*        # words with optional internal hyphens
...   | \$?\d+(\.\d+)?%?  # currency and percentages, e.g. $12.40, 82%
...   | \.\.\.            # ellipsis
...   | [][.,;"'?():-_`]  # these are separate tokens; includes ], [
... '''
>>> nltk.regexp_tokenize(text, pattern)
[('', '', ''), ('', '', ''), ('', '-print', ''), ('', '', …
Run Code Online (Sandbox Code Playgroud)

python regex pattern-matching nltk

7
推荐指数
1
解决办法
6206
查看次数

带有 React 和 Konva 的响应式画布

我使用 React 和 Konva 库来画一条简单的线。但是当我调整屏幕大小时,线条会留在屏幕之外。那么,我怎样才能让它响应呢?

这是我的代码:

import React from "react";
import { Stage, Layer,Line } from 'react-konva';

class App extends React.Component {

  constructor(props) {
    super(props);
  }

  render() {
    return (
        <div>
            <Stage width={window.innerWidth} height={window.innerHeight}>
                <Layer>
                    <Line
                        x={100}
                        y={100}
                        points={[0,0,576,456,509,403,20,15,300,207,111,222,293,177]}
                        stroke="black"
                        strokeWidth={5}
                        ref="line"
                    />
                </Layer>
            </Stage>
        </div>
    );
  }
}

export default App;
Run Code Online (Sandbox Code Playgroud)

javascript line reactjs konvajs responsive

1
推荐指数
1
解决办法
4118
查看次数