조건이 있는 곳에 이 의사코드를 작성하는 방법

조건이 있는 곳에 이 의사코드를 작성하는 방법

이 질문은 이 질문의 확장입니다.디렉토리 나열 문제. 본문의 원래 부분을 이해해야 하는 문제가 있습니다.

전류 출력

여기에 이미지 설명을 입력하세요.

두 번째 질문은 말이 되지 않는다는 것을 알 수 있습니다. 그것은에 포함되어 있습니다subsection 다카야스 동맥염류마티스 디렉토리:

\subsection{Takayasu arteritis}

\begin{question}
{You get a patient. 
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}

Lorem ipsum.    

\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye. 
So special eye diagnosis done. 
Affects eye.
\end{question}

현재 출력이 너무 훌륭합니다.암호

\section{Rheumatology}  

\begin{question}
{You get a patient. 
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}

\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye. 
So special eye diagnosis done. 
Affects eye.
\end{question}

하지만 그랬으면 좋겠어

\section{Rheumatology}  

\subsection{Takayasu arteritis}

\begin{question}
{You get a patient. 
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}

\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye. 
So special eye diagnosis done. 
Affects eye.
\end{question}

내 제안은 하위 섹션에 문제가 있으면 하위 섹션을 포함해야 한다는 것입니다.

내 의사 코드

Look for the environment \begin{question}...\end{question}.
See the subsection of the question (it locates above the question). 
   If there is no subsection, leave blank. 
   If there are many questions within one subsection, put only one subsection. 

테든의 코드

#!/usr/bin/env bash

## avoid errors if a directory has no *tex files
shopt -s nullglob

directories=("Cardiology" "Rheumatology" "Surgery");

## Change this to set whichever options you want.
printf "%s\n%s\n" "\documentclass{YOURCLASS}" "\begin{document}"

for directory in ${directories[@]}
do
    ## Reset the counter, avoid empty sections.
    c=0;
    for file in "$directory"/*tex
    do
        let c++
        [ "$c" -eq 1 ] && printf "\n%s\n" "\section{$directory}"
        ## Extract the wanted lines
        perl -lne '$a=1 && print "" if /\\begin{question}/; 
                  print if $a==1;
                  $a=0 if /\\end{question}/;' "$file" 
        echo ""
    done
done
echo "\end{document}"

나는 이 줄의 논리가 바뀌어야 한다고 생각한다.

        ## Extract the wanted lines
        perl -lne '$a=1 && print "" if /\\begin{question}/; 
                  print if $a==1;
                  $a=0 if /\\end{question}/;' "$file" 
        echo ""

정규식을 사용하여 파일의 모든 문제를 찾고 문제 하위 섹션을 무시합니다.

데이터 예시(기존 케이스와는 조금 다릅니다!)

\subsection{Takayasu arteritis}

\begin{question}
{You get a patient. 
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}

\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye. 
So special eye diagnosis done. 
Affects eye.
\end{question}


Fever of unknown origin can be used when you do not know what is causing the disease. 

% Show cases in MedScape and ask class. 

Aneurysms. 


\subsubsection{Treatment}

\begin{question}
{What you should always include in Takayasu treatment? 
What are the symptoms?}
Blood pressure.
Aneurysms which will burst without treatment. 
So blood pressure decreasing drugs like beta blockers along in combination with other drugs.
\end{question}

\begin{question}
{When is the checkup of the Takayasu arteritis?} 
Only once per year. 
You could expect every month like normally in this kind of diseases.
But only once per year.
\end{question}

애플리케이션의 섹션을 무시할 수 있는 곳입니다.

의사코드를 어떻게 작성할 수 있나요?


Terdon 코드의 버그가 2014년 10월 14일에 발견되었습니다.

오류를 일으킨 데이터의 예

\subsection{3}
A 55 y.o male says that for the last year ... 

\begin{question}
{What is the pathogenetic mechanism of his complains?} 
\end{question}

Terdon의 코드를 구문 분석하면 정확히 동일한 결과가 나오지만 이 문장은 잘못된 것입니다.55세..더 이상 최종 결과에 나타나지 않아야 합니다. 섹션과 본문 사이에 입력이 있으면 올바르게 출력됩니다. 그러나 이것은 가정할 수 없습니다.

이 오류의 원인은 Windows 기호가 이동되었기 때문입니다.여기.

답변1

나는 원래 원래 코드를 확장하려고 했지만 이제는 Perl에서 모든 것을 다시 구현하는 것이 훨씬 쉬운 지점에 도달했습니다.

#!/usr/bin/env perl

## This is the path to the target  directories
my $path="/Users/Masi/Dropbox/";

## The target directories
my @directories=("Cardiology","Rheumatology","Surgery");

## Iterate over the directories
foreach my $dir (@directories) {
    my $dd=0;
    ## Read the current directory
    opendir (my $DIR, "$path/$dir");
    ## Find all files in this directory
    while (my $file = readdir($DIR)) {
        ## Reset the counter
        my $c=0;
        ## Skip any files that aren't .tex
        next unless $file =~ /\.tex$/;

        ## Open the file
        open(my $fh,"$path/$dir/$file");

        while (<$fh>) {
            ## Get the subsection. $_ is the current line.
            $sub="$_" and $n=0 if /\\subsection{/;
            ## If this line is a question
            if (/\\begin{question}/) {
                ## If this counter is 0, this is the first file
                ## of this directory, so print the section
                ## Print the section name
                if ($dd==0) {
                    print "\\section{$dir}\n\n";
                    $dd++;
                } 
                ## If this counter is 0, this is the first question
                ## of this subsection, so print the subsection line
                print "$sub\n" if $n==0;

                $n++;
                ## Increment the counter, we want these lines
                $c++;
                ## And print
                print;
            }
            else {
                ## Print lines if the counter is 1
                print if $c==1;
                ## reset the counter to 0
                print "\n" and $c=0 if /\\end{question}/;
            }
        }
        print "\n";
    }

}

이는 하위 섹션을 무시하지만 하위 섹션을 포함하도록 쉽게 수정할 수 있습니다.

답변2

terdon의 코드 확장 또는 개선어떤 논리를 바탕으로답변

#!/usr/bin/env perl

## This is the path to the target  directories
my $path="/Users/Masi/Dropbox/";
chdir $path or die "cannot chdir '$path'";

## Iterate over the directories
foreach my $dir (
    "Cardiology", "Pathophysiology", "Patology and Biopsy", "Physiology",
    "Propedeutics", "Radiology", "Rheumatology", "Surgery"
)
{
    my $dd=0;
    ## Read the current directory
    opendir my $DIR, $dir or die "cannot opendir '$dir'";

    ## Find all files in this directory
    while (my $file = readdir($DIR)) {
        ## Reset the counter
        my $c=0;
        ## Skip any files that aren't .tex
        next unless $file =~ /\.tex$/;

        ## Open the file
        open(my $fh,"$path/$dir/$file");

        while (<$fh>) {
            ## Get the subsection. $_ is the current line.
            $sub="$_" and $n=0 if /\\subsection{/;
            ## If this line is a question
            if (/\\begin{question}/) {
                ## If this counter is 0, this is the first file
                ## of this directory, so print the section
                ## Print the section name
                if ($dd==0) {
                    print "\\section{$dir}\n\n";
                    $dd++;
                }
                ## If this counter is 0, this is the first question
                ## of this subsection, so print the subsection line
                print "$sub\n" if $n==0;

                $n++;
                ## Increment the counter, we want these lines
                $c++;
                ## And print
                print;
            }
            else {
                ## Print lines if the counter is 1
                print if $c==1;
                ## reset the counter to 0
                print "\n" and $c=0 if /\\end{question}/;
            }
        }
        print "\n";
    }
    closedir $DIR  or die "cannot closedir '$dir'";
}

여기에 오류 관리를 추가했습니다.

관련 정보