У меня есть текстовый файл, содержащий каталог курсов всех курсов CS. Фактический курс сам по себе довольно прост, потому что он находится в начале линии и начинается с курса. Предварительное условие для меня немного сложнее. Я могу найти строку, в которой есть предпосылки, но курсы prereq могут быть одно или несколько и разделены запятыми и «и». Иногда также существует строка после предложения prereq, которая содержит другие имена курсов, но не самого prereq. Вот пример того, что файл PREREQ выглядит следующим образом:Какое правильное выражение для этого шаблона?
CS 4213. Computing for Bioinformatics. (3-0) 3 Credit Hours.
Prerequisite: CS 1173 or another programming course. Emphasizes computing tasks common in bioinformatics: variables, flow control, input/output, strings, pattern matching, arrays, hash tables, functions, access to databases, and parsing data from queries for common bioinformatics tasks. SQL, XML, and BioPerl. May not be applied to the 24 hours of required electives for computer science majors, but may be included for a computer science minor.
CS 4313. Automata, Computability, and Formal Languages. (3-0) 3 Credit Hours.
Prerequisites: CS 3341 and CS 3343. Discussion of abstract machines (finite state automata, pushdown automata, and Turing machines), formal grammars (regular, context-free, and type 0), and the relationship among them.
CS 4353. Unix and Network Security. (3-0) 3 Credit Hours.
Prerequisite: CS 3433. A technical survey of the fundamentals of computer and information security. Issues include cryptography, authentication, attack techniques at both the OS and network level, defense techniques, intrusion detection, scan techniques and detection, forensics, denial of service techniques and defenses, libpcap, libdnet and libnet programming.
CS 4363. Cryptography. (3-0) 3 Credit Hours.
Prerequisites: CS 3341, CS 3343, and CS 3433. A course in pure and applied cryptography, with emphasis on theory. Topics may include conventional and public-key cryptosystems, signatures, pseudo-random sequences, hash functions, key management, and threshold schemes.
CS 4383. Computer Graphics. (3-0) 3 Credit Hours.
Prerequisites: CS 2121, CS 2123, CS 3341, and CS 3343. An introduction to two- and three-dimensional generative computer graphics. Display devices, data structures, mathematical transformations, and algorithms used in picture generation, manipulation, and display.
CS 4393. User Interfaces. (3-0) 3 Credit Hours.
Prerequisite: CS 3443. Study of advanced user interface issues. User interface design, human factors, usability, GUI programming models, and the psychological aspects of human-computer interaction.
CS 4413. Web Technologies. (3-0) 3 Credit Hours.
Prerequisites: CS 3421 and CS 3423. Fundamentals of Web and component technology: markup languages, layout design, client and server side programming, database and Web integration.
CS 4593. Topics in Computer Science. (3-0) 3 Credit Hours.
Prerequisite: Consent of instructor. Advanced topics in an area of computer science. May be repeated for credit when topics vary.
CS 4633. Simulation. (3-0) 3 Credit Hours.
Prerequisites: CS 3341 and CS 3343. Design, execution, and analysis of simulation models, discrete event simulation techniques, input and output analysis, random numbers, and simulation tools and languages.
CS 4713. Compiler Construction. (3-0) 3 Credit Hours.
Prerequisites: CS 3341, CS 3343, CS 3841, and CS 3843. An introduction to implementation of translators. Topics include formal grammars, scanners, parsing techniques, syntax-directed translation, symbol table management, code generation, and code optimization. (Formerly titled “Compiler Writing.”).
Это то, что я прямо сейчас:
Pattern p = Pattern.compile("^(CS [0-9][0-9][0-9][0-9]).*");
Pattern p2 = Pattern.compile("^Prereq.* ([A-Z]* [0-9][0-9][0-9][0-9]).*");
while ((line = br.readLine()) != null) {
Matcher m = p.matcher(line);
if (m.find()) {
System.out.println(m.group(1));
}
Matcher m2 = p2.matcher(line);
if (m2.find()) {
System.out.println("Prereq: "+m2.group(1)+", Occurrences: "+m2.groupCount());
//System.out.println(line);
}
}
И до сих пор это становится все курсы и первой предпосылкой или NONE если не являются предварительными условиями для курса.
Пример вывода:
CS 4213
Prereq: CS 1173, Occurrences: 1
CS 4313
Prereq: CS 3343, Occurrences: 1
CS 4353
Prereq: CS 3433, Occurrences: 1
CS 4363
Prereq: CS 3433, Occurrences: 1
CS 4383
Prereq: CS 3343, Occurrences: 1
CS 4393
Prereq: CS 3443, Occurrences: 1
CS 4413
Prereq: CS 3423, Occurrences: 1
CS 4593
CS 4633
Prereq: CS 3343, Occurrences: 1
CS 4713
Prereq: CS 3843, Occurrences: 1
Так скажем, 4313, я хотел бы CS 3341 и CS 3343
Можете ли вы уточнить, что вы пытаетесь совместить? Курс и список предварительных курсов? – Matt
Да, я получил «Pattern p», чтобы соответствовать курсу, но «Pattern p2» соответствует только первому вступлению в курс prereq. – MeesterMarcus